How to export and import style in npm package?

I have a response component and I publish the component in the NPM registry that I create with webpack. In my main project, I used the JS npm package component as follows:

Import myComp from 'myComp';

The problem is that myComp also has CSS, which I embed in dist/index.cssusing webpack and ExtractTextPlugin (which build all css into one file).

And I want to use the style as follows:

Import 'myComp/index.css';

or

Import 'myComp/index';

And in the myComp npm package, I want to expose it in a way that this import method will support.

NOTE. I do not want to import it directly fromnode_modules

Import '../../../node_modules/myComp/index.css'; // bad

Thank!

+4
source share
1 answer

, , , , , - CSS ( ):

import 'myComp/dist/style.css';

, (browserify/webpack ..) lss css javascript.

, .


, npm, "" package.json. , npm.

files: [
"dist/*.css"
]

, : https://github.com/rotundasoftware/parcelify - https://www.npmjs.com/package/parcelify-loader - webpack

. npm.

+4
source

Source: https://habr.com/ru/post/1659556/


All Articles