Publish an npm package that requires CSS from node_modules

The React component I'm trying to publish to npm requires a CSS stylesheet from one of my project's dependencies in node_modules . Basically, my index.js file (which provides my component to the outside world) looks like this:

 import Gallery from './containers/GalleryContainer'; require('../../node_modules/jscrollpane/style/jquery.jscrollpane.css'); export default Gallery; 

This works in my webpack based environment because webpack picks up a CSS file and injects it into the DOM (using css-loader and style-loader), but if I'm not sure how to pack it for distribution, I want to publish the package like ES5 and I want users to be able to use it in the context of ES6 (using webpack / browsify) or directly in the browser.

So far, I have been transferring my ES6 code to ES5 from Babel to my prepublish lib folder. This takes care of javascript, but not the CSS that it requires.

Should I give my library users a CSS link manually or is there a way for the require statement to be portable?

+5
source share

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


All Articles