Home

Awesome

csjs-extractify

build status coverage status dependencies status

Browserify plugin to extract csjs into an external css bundle at build time

Usage

To use this plugin, create a seperate files for each CSJS module. For example:

main.csjs.js

const csjs = require('csjs');

module.exports = csjs`

.foo {
  color: red;
}

`;

When bundling your app, all exported CSJS will be extracted into a single, static CSS bundle.

Options

  --extension    [default: '.csjs.js']
  The file extension of your CSJS modules

  --output
  The path to write the output css bundle

CLI usage

browserify -p [ csjs-extractify -o dist/main.css ] index.js

API usage

Write to file:

const browserify = require('browserify');
const extractify = require('csjs-extractify');

const b = browserify('./main.js');
b.plugin(extractify, {output: './dist/scoped.css'});
b.bundle();

Or grab output stream:

const fs = require('fs');
const browserify = require('browserify');
const extractify = require('csjs-extractify');

const b = browserify('./main.js');
b.plugin(extractify);

const bundle = b.bundle();
bundle.on('extracted_csjs_stream', css => {
  css.pipe(fs.createWriteStream('scoped.css'));
});

Limitations

More sophisticated extraction is being worked on, but this should cover many use cases for now.