项目作者: Evercoder

项目描述 :
Rollup plugin to extract CSS into a single external file.
高级语言: JavaScript
项目地址: git://github.com/Evercoder/rollup-plugin-css-bundle.git
创建时间: 2018-04-20T09:39:58Z
项目社区:https://github.com/Evercoder/rollup-plugin-css-bundle

开源协议:MIT License

下载


rollup-plugin-css-bundle

A Rollup plugin whose sole purpose is to collect all the CSS files you import into your project and bundle them into a single glorious CSS file. Refreshingly, it preserves the order in which the CSS files are imported. Soberingly, it does not generate source maps.

Installation

npm version

  1. # using npm
  2. npm install --save-dev rollup-plugin-css-bundle
  3. # using yarn
  4. yarn add --dev rollup-plugin-css-bundle

Usage

In your rollup.config.js file:

  1. import cssbundle from 'rollup-plugin-css-bundle';
  2. export default {
  3. input: 'index.js',
  4. output: {
  5. file: 'dist/index.js',
  6. format: 'cjs'
  7. },
  8. plugins: [cssbundle()]
  9. };

Like all well-behaved Rollup plugins, cssbundle supports the include and exclude options that filter the files on which the plugin should run.

output: String is an optional path for the extracted CSS; when ommitted, we use the bundle’s file name to fashion a path for the bundled CSS.

transform: Function is available for processing the CSS, such as with postcss. It receives a string containing the code to process as its only parameter, and should return the processed code. Par exemple:

  1. // rollup.config.js
  2. import cssbundle from 'rollup-plugin-css-bundle';
  3. import postcss from 'postcss';
  4. import autoprefixer from 'autoprefixer';
  5. export default {
  6. input: 'index.js',
  7. output: {
  8. file: 'dist/index.js',
  9. format: 'cjs'
  10. },
  11. plugins: [
  12. cssbundle({
  13. transform: code => postcss([autoprefixer]).process(code, {})
  14. })
  15. ]
  16. };

That’s it. Enjoy! ✌️