how to export and import style in npm package? how to export and import style in npm package? node.js node.js

how to export and import style in npm package?


So it's easier than I thought, all you need to do is import the CSS like that (as I did in the question):

import 'myComp/dist/style.css';

And make sure your tools (browserify/webpack etc..) can handle loading css into your javascript file.

So the issue was more related to the building process.


Also, if you want to push specific code into npm registry you can use "files" inside package.json. This way you'll end up with just the files you need in npm registry.

files: ["dist/*.css"]

You can also use tools like:https://github.com/rotundasoftware/parcelify - for browserify https://www.npmjs.com/package/parcelify-loader - for webpack

But I didn't like them. It forces a dependency on the consumer of your npm package.