0

I'm trying to import an npm package into my vue-cli dev site. Here are the instructions provided by the package website:

enter image description here

It says that it needs the css and js files to be included somewhere in the code. How would I go about doing this?

I'm guessing the css file is included by putting this in App.vue:

<style>
  @import '../node_modules/swiper/dist/css/swiper.min.css';
....
</style>

Is that right? How would I include the .js file? Inside App.vue, or main.js? I'm honestly not sure how the syntax for that would go either.

Here is my index.html file:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="build/swiper.min.css">
  </head>
  <body>
    <div id="app"></div>
    <script src="build/swiper.min.js"></script>
  </body>
</html>

2 Answers 2

0

you can include these files in build/index.htmllike common js and css

<head> 
....
 <link rel="stylesheet" href="path_to_css/idangerous.swiper.css">
 <script defer src="path_to_js/idangerous.swiper-2.x.min.js"></script> 
.... 
</head>
Sign up to request clarification or add additional context in comments.

3 Comments

This throws a 404 error in development mode, unfortunately.
you can take these two files into build foler,
sorry I see the code after you remind me, it is my fault; you should use relative path, <link rel="stylesheet" href="./swiper.min.css"><script src="./swiper.min.js"></script>
0

This seems to be working - in my main.js file, I've included the js and css files like this:

import Swiper from 'swiper'
import 'swiper/dist/css/swiper.min.css'

As far as I can tell, this is correctly importing the npm package into the project for use in development and production.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.