C1rcu1tB04rd
C1rcu1tB04rd

Reputation: 126

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.

Upvotes: 1

Views: 1585

Answers (1)

Yvonne Aburrow
Yvonne Aburrow

Reputation: 2728

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

e.g.

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.

Upvotes: 1

Related Questions