Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rollup-plugin-css-porter

RJHwang8.3kMIT1.0.2

A rollup plugin to collect all the imported css file

rollup, rollup-plugin, css

readme

rollup-plugin-css-porter

A rollup plugin to collect and combine all the imported css file. Such as import './my.css'. Then output them to a standalone css file. Besides, use clean-css to create a minified css file as you wish.

Supported rollup version :

plugin version rollup version
1.x 1.0.0+
0.3.x 0.48.0~0.68.2
0.1.0~0.2.x 0.36.0~0.47.6

Installation

Use npm:

npm install --save-dev rollup-plugin-css-porter
// or
npm i -D rollup-plugin-css-porter

Use yarn:

yarn add rollup-plugin-css-porter --dev

Plugin options

Name ValueType Required Description
dest String false Default value is the same dir of 'bundle.write(options)' options.file
raw Boolean
String
false 1. Boolean value means whether output a raw css file, default value is true
2. String value means output raw css file to this path
minified Boolean
String
false 1. Boolean value means whether output a minified css file, default value is true
2. String value means output minified css file to this path

If set raw or minified option to a String value, dest option will be ignored.

Usage

Case 1 (default behavior):

Output to a standalone css file and a minified css file. The output destination is the same dir of 'bundle.write(options)' options.file.

import { rollup } from 'rollup';
import css from 'rollup-plugin-css-porter';

rollup({
  input: 'main.js',
  plugins: [ css() ]
}).then(bundle => {
  bundle.write({
    format: 'es',
    file: 'bundle.js'
  });
});

Case 2:

Output to a standalone css file without minified css file. The output destination is the same dir of 'bundle.write(options)' options.file.

import { rollup } from 'rollup';
import css from 'rollup-plugin-css-porter';

rollup({
  input: 'main.js',
  plugins: [ css({minified: false}) ]
}).then(bundle => {
  bundle.write({
    format: 'es',
    file: 'bundle.js'
  });
});

Case 3:

Output to a specific path if config the plugin options.dest.

import { rollup } from 'rollup';
import css from 'rollup-plugin-css-porter';

rollup({
  input: 'main.js',
  plugins: [ css({dest: 'path-to-my-dir/bundle.css'}) ]
}).then(bundle => {
  bundle.write({
    format: 'es',
    file: 'bundle.js'
  });
});

Case 4:

Output to a standalone css file with only minified css file. The output destination is the same dir of 'bundle.write(options)' options.file.

import { rollup } from 'rollup';
import css from 'rollup-plugin-css-porter';

rollup({
  input: 'main.js',
  plugins: [ css({raw: false}) ]
}).then(bundle => {
  bundle.write({
    format: 'es',
    file: 'bundle.js'
  });
});

Case 5:

Custom output filenames by config a string value for plugin raw and minified option :

import { rollup } from 'rollup';
import css from 'rollup-plugin-css-porter';

rollup({
  input: 'main.js',
  plugins: [ css({
    raw: 'custom.css',
    minified: 'custom.min.css',
  }) ]
}).then(bundle => {
  bundle.write({
    format: 'es',
    file: 'bundle.js'
  });
});

Or:

css({
  raw: 'custom.css',
  minified: false,
})

Or:

css({
  raw: false,
  minified: 'custom.min.css',
})

Build

Use npm:

npm run build

Use yarn:

yarn run build

Run test

Use npm:

npm test

Use yarn:

yarn test

changelog

rollup-plugin-css-porter changelog

1.0.2 2019-03-13

  • Polishing README - add plugin options
  • Polishing README - fixed docs error

1.0.1 2019-03-13

  • Polishing README - add supported rollup version

1.0.0 2019-03-12

  • Upgrade to support rollup-1.x (test pass from rollup 1.0.0 to 1.6.0)

0.3.0 2019-03-12

  • Upgrade to rollup-0.68.2

    This is the latest supported rollup version on 0.3.x, because from rollup-1.0.0+, rollup-plugin api changed. Supported rollup version from 0.48.0 to 0.68.2.

0.2.1 2019-03-11

  • Upgrade to rollup-0.47.6

    This is the latest supported rollup version on 0.2.x, because from rollup-0.48.0+, the options param in bundle.write(options), options.dest be renamed to options.file. Note that from rollup-0.38.0, you will see some test log 'Generated an empty bundle' output to the console.

0.2.0 2019-01-04

  • Support minified output only by setting option raw=false
  • Support raw output only by setting option minified=false
  • Support custom output file name by setting option raw="custom.css" or minified="custom.min.css"

0.1.2 2017-02-23

  • fixed css content cache for issue#1
  • polish README.md

0.1.1 2016-12-08

  • polish README.md

0.1.0 2016-12-08

  • initial