rollup-plugin-css-bundle
Advanced tools
Comparing version 1.0.3 to 1.0.4
# Changelog | ||
#### 1.0.4 | ||
Uses the `generateBundle` hook rather than the deprecated `ongenerate` and `onwrite` hooks. ([#3](https://github.com/Evercoder/rollup-plugin-css-bundle/pull/3) by [@iamDecode](https://github.com/iamDecode)) | ||
#### 1.0.3 | ||
Makes the plugin compatible with recent versions of Rollup, currently 0.6.66. ([#1](https://github.com/Evercoder/rollup-plugin-css-bundle/issues/1), [#2](https://github.com/Evercoder/rollup-plugin-css-bundle/pulls/2) — thanks [@iamDecode](https://github.com/iamDecode)!) |
@@ -11,3 +11,2 @@ 'use strict'; | ||
let styles = {}; | ||
let bundles = {}; | ||
@@ -38,26 +37,24 @@ const options = Object.assign( | ||
ongenerate(opts, bundle) { | ||
// Depending on the Rollup version, | ||
// the `modules` will be either an array | ||
// or an object with key-value pairs. | ||
let modules = Array.isArray(bundle.modules) | ||
? bundle.modules | ||
: Object.getOwnPropertyNames(bundle.modules); | ||
let css = Object.entries(styles) | ||
.sort((a, b) => modules.indexOf(a[0]) - modules.indexOf(b[0])) | ||
.map(entry => entry[1]) | ||
.join('\n'); | ||
bundles[opts.file] = css; | ||
}, | ||
generateBundle(opts, bundle) { | ||
for (const file in bundle) { | ||
// Depending on the Rollup version, | ||
// the `modules` will be either an array | ||
// or an object with key-value pairs. | ||
let modules = Array.isArray(bundle[file].modules) | ||
? bundle[file].modules | ||
: Object.getOwnPropertyNames(bundle[file].modules); | ||
let css = Object.entries(styles) | ||
.sort((a, b) => modules.indexOf(a[0]) - modules.indexOf(b[0])) | ||
.map(entry => entry[1]) | ||
.join('\n'); | ||
onwrite(opts) { | ||
fs.outputFile( | ||
options.output || | ||
fs.outputFile( | ||
options.output || | ||
path.join( | ||
path.dirname(opts.file), | ||
path.basename(opts.file, path.extname(opts.file)) + | ||
'.css' | ||
path.basename(file, path.extname(opts.file)) + '.css' | ||
), | ||
bundles[opts.file] | ||
); | ||
css | ||
); | ||
} | ||
} | ||
@@ -64,0 +61,0 @@ }; |
{ | ||
"name": "rollup-plugin-css-bundle", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A Rollup plugin to extract CSS into a single external file", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# rollup-plugin-css-bundle | ||
A [Rollup](https://github.com/rollup/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. | ||
A [Rollup](https://github.com/rollup/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 | ||
<a href="https://www.npmjs.org/package/rollup-plugin-css-bundle"><img src="https://img.shields.io/npm/v/rollup-plugin-css-bundle.svg?style=flat" alt="npm version"></a> | ||
```bash | ||
# using npm | ||
npm install --save-dev rollup-plugin-css-bundle | ||
# using yarn | ||
yarn add --dev rollup-plugin-css-bundle | ||
``` | ||
## Usage | ||
In your **rollup.config.js** file: | ||
```js | ||
// rollup.config.js | ||
import cssbundle from 'rollup-plugin-css-bundle'; | ||
@@ -17,13 +30,11 @@ | ||
}, | ||
plugins: [ | ||
cssbundle() | ||
] | ||
} | ||
plugins: [cssbundle()] | ||
}; | ||
``` | ||
Like all well-behaved Rollup plugins, cssbundle supports the __include__ and __exclude__ options that filter the files on which the plugin should run. | ||
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. | ||
**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](https://github.com/postcss/postcss). It receives a string containing the code to process as its only parameter, and should return the processed code. _Par exemple_: | ||
**transform**: _Function_ is available for processing the CSS, such as with [postcss](https://github.com/postcss/postcss). It receives a string containing the code to process as its only parameter, and should return the processed code. _Par exemple_: | ||
@@ -30,0 +41,0 @@ ```js |
@@ -7,3 +7,2 @@ import fs from 'fs-extra'; | ||
let styles = {}; | ||
let bundles = {}; | ||
@@ -34,28 +33,26 @@ const options = Object.assign( | ||
ongenerate(opts, bundle) { | ||
// Depending on the Rollup version, | ||
// the `modules` will be either an array | ||
// or an object with key-value pairs. | ||
let modules = Array.isArray(bundle.modules) | ||
? bundle.modules | ||
: Object.getOwnPropertyNames(bundle.modules); | ||
let css = Object.entries(styles) | ||
.sort((a, b) => modules.indexOf(a[0]) - modules.indexOf(b[0])) | ||
.map(entry => entry[1]) | ||
.join('\n'); | ||
bundles[opts.file] = css; | ||
}, | ||
generateBundle(opts, bundle) { | ||
for (const file in bundle) { | ||
// Depending on the Rollup version, | ||
// the `modules` will be either an array | ||
// or an object with key-value pairs. | ||
let modules = Array.isArray(bundle[file].modules) | ||
? bundle[file].modules | ||
: Object.getOwnPropertyNames(bundle[file].modules); | ||
let css = Object.entries(styles) | ||
.sort((a, b) => modules.indexOf(a[0]) - modules.indexOf(b[0])) | ||
.map(entry => entry[1]) | ||
.join('\n'); | ||
onwrite(opts) { | ||
fs.outputFile( | ||
options.output || | ||
fs.outputFile( | ||
options.output || | ||
path.join( | ||
path.dirname(opts.file), | ||
path.basename(opts.file, path.extname(opts.file)) + | ||
'.css' | ||
path.basename(file, path.extname(opts.file)) + '.css' | ||
), | ||
bundles[opts.file] | ||
); | ||
css | ||
); | ||
} | ||
} | ||
}; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7069
62
99