简体   繁体   中英

How to include a css/js file from a node package?

I have in stalled an npm package . Now I want to include the css and js files in my html page by typing something like this:

      <link href="/root/node_modules/quill/dist/quill.snow.css" rel="stylesheet">

But the above path does not work. My html page is located at /var/www/html What is the right way to do this. This is probably a duplicate but I am not able to find the answer.

You need to make sure that your CSS and JS files are in the same directory (probably src/app ) as your HTML files.

eg

src
 |
 | app
    |
    | css
    | js
   index.html

so the path to index.html in the web version is /index.html , and the path (relative to index.html ) to the CSS folder is ./css .

Here's a great explanation of relative paths in node applications .

When using 3rd-party libraries such as CSS in node modules, you can use this in your stylesheet:

@import "~quill/dist/quill.snow";

You will also need to require the module in your config file - see this discussion in GitHub for more info .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM