Home

Awesome

rollup-plugin-stylus-css-modules

Build Status

A Rollup.js plugin to compile Stylus and inject CSS Modules.

Installation

$ npm install --save-dev rollup-plugin-stylus-css-modules

Usage

Add the following code to your project's rollup.config.js:

import stylusCssModules from 'rollup-plugin-stylus-css-modules';

export default {
  entry: 'index.js',
  plugins: [
    stylusCssModules({
      output: 'styles.css'
    })
  ]
};

in Stylus

.container
  height 100%

in JS

import styles from './styles.styl';
const container = `<div class="${styles.container}">...</div>`;

Options

Use with external tools

Combination with external tools, such as PostCSS works perfectly.

stylusCssModules({
  sourceMap: true,
  output: (css) => {
    return postcss([
      // postcss' plugins...
    ]).process(css, {
      map: true
    }).then((result) => {
      fs.writeFileSync('styles.css', result.css);
    });
  }
});

Use with other CSS plugins

You can also use the Rollup.js plugin, such as rollup-plugin-postcss, rollup-plugin-css-only, etc.

export default {
  entry: 'index.js',
  plugins: [
    stylusCssModules(),
    postcss()
  ]
};

License

MIT