I am building a repo that will be available on npm. The repo consists of several modules similar to react-leaflet and react-d3 . Application developers will include modules from the npm package through require / import , for example:
import { ModuleOne, ModuleTwo } from 'myNpmPackage`;
I need to pack CSS together with each of these modules and that CSS will be compiled from Sass files in each module.
Given the folder structure for myNpmPackage , for example:
βββ src β βββ ModuleOne β β βββ index.js β β βββ style.scss β βββ ModuleTwo β β βββ index.js β β βββ style.scss βββ package.json
What is a good publishing stream to make these .scss files (compiled into .css ) accessible to myNpmPackage consumers without requiring users to explicitly include / @import / link rel="stylesheet" CSS?
I use gulp and browserify and prefer to stick with this pipeline.
UPDATE: I found parcelify doing some of what I need. I am adding the following to myNpmPackage/package.json :
"style": "src/**/*.scss", "transforms": [ "sass-css-stream" ]
and add parcelify to dependencies so that it is installed along with myNpmPackage .
Consumers of myNpmPackage should add the following to their gulpfile :
parcelify(b, { bundles: { style: './build/modules.css' } });
parcelify will use glob "style" in myNpmPackage/package.json to round off all .scss files in .scss modules and myNpmPackage them out to ./build/modules.css .
This happens, but not perfect, for two reasons:
- CSS files from each module are included in the consumer application assembly, even if not all modules are included;
- This strategy requires the application developer to add code to his
gulpfile instead of just working.