I'm putting together a repo that will be available on npm. The repo consists of multiple modules, similar to react-leaflet and react-d3. Application developers will include modules from within the npm package via require
/import
, e.g.:
import { ModuleOne, ModuleTwo } from 'myNpmPackage`;
I need to package CSS along with each of these modules, and that CSS will be compiled from Sass files within each module.
Given a folder structure for myNpmPackage
like:
├── src
│ ├── ModuleOne
│ │ ├── index.js
│ │ ├── style.scss
│ ├── ModuleTwo
│ │ ├── index.js
│ │ ├── style.scss
├── package.json
What is a good publish flow to make those .scss
files (compiled into .css
) available to consumers of myNpmPackage
, without requiring that consumers explicitly include / @import
/ link rel="stylesheet"
the CSS?
I'm using gulp and browserify and would prefer to stick with that pipeline.
UPDATE: I've found parcelify
does some of what I need. I add the following to myNpmPackage/package.json
:
"style": "src/**/*.scss",
"transforms": [
"sass-css-stream"
]
and add parcelify
to dependencies
, so that it's installed along with myNpmPackage
.
Consumers of myNpmPackage
must then add the following to their gulpfile
:
parcelify(b, {
bundles: {
style: './build/modules.css'
}
});
parcelify
will use the "style"
glob in myNpmPackage/package.json
to round up all the .scss
files in myNpmPackage
's modules and bundle them into ./build/modules.css
.
This is getting there, but not ideal for two reasons:
- The CSS files from each module are all included in the consumer application build, even if not all the modules are included;
- This strategy requires the consumer application developer to add code to their
gulpfile
instead of "just working".