rollup-plugin-css-bundle
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -9,11 +9,13 @@ 'use strict'; | ||
var index = (opts) => { | ||
var index = opts => { | ||
let styles = {}; | ||
let bundles = {}; | ||
const options = Object.assign({ | ||
include: ['**/*.css'], | ||
transform: code => code | ||
}, opts); | ||
const options = Object.assign( | ||
{ | ||
include: ['**/*.css'], | ||
transform: code => code | ||
}, | ||
opts | ||
); | ||
@@ -37,4 +39,10 @@ const filter = utils.createFilter(options.include, options.exclude); | ||
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) => bundle.modules.indexOf(a[0]) - bundle.modules.indexOf(b[0])) | ||
.sort((a, b) => modules.indexOf(a[0]) - modules.indexOf(b[0])) | ||
.map(entry => entry[1]) | ||
@@ -47,13 +55,14 @@ .join('\n'); | ||
fs.outputFile( | ||
options.output || | ||
path.join( | ||
path.dirname(opts.file), | ||
path.basename(opts.file, path.extname(opts.file)) + '.css' | ||
), | ||
options.output || | ||
path.join( | ||
path.dirname(opts.file), | ||
path.basename(opts.file, path.extname(opts.file)) + | ||
'.css' | ||
), | ||
bundles[opts.file] | ||
); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
module.exports = index; |
{ | ||
"name": "rollup-plugin-css-bundle", | ||
"version": "1.0.2", | ||
"main": "dist/index.js", | ||
"module": "src/index.js", | ||
"repository": "git@github.com:danburzo/rollup-plugin-css-bundle.git", | ||
"author": "Dan Burzo <danburzo@gmail.com>", | ||
"keywords": [ | ||
"rollup-plugin" | ||
], | ||
"license": "MIT", | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"devDependencies": { | ||
"rollup": "^0.58.1" | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^5.0.0", | ||
"rollup-pluginutils": "^2.0.1" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"watch": "rollup -w -c" | ||
} | ||
"name": "rollup-plugin-css-bundle", | ||
"version": "1.0.3", | ||
"description": "A Rollup plugin to extract CSS into a single external file", | ||
"main": "dist/index.js", | ||
"module": "src/index.js", | ||
"repository": "Evercoder/rollup-plugin-css-bundle", | ||
"author": "Dan Burzo <danburzo@gmail.com>", | ||
"keywords": [ | ||
"rollup-plugin", | ||
"css" | ||
], | ||
"license": "MIT", | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"devDependencies": { | ||
"husky": "^1.1.2", | ||
"prettier": "1.14.3", | ||
"pretty-quick": "^1.8.0", | ||
"rollup": "^0.66.6" | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^5.0.0", | ||
"rollup-pluginutils": "^2.0.1" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"watch": "rollup -w -c", | ||
"release": "yarn build && yarn publish" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "pretty-quick --staged" | ||
} | ||
}, | ||
"prettier": { | ||
"bracketSpacing": true, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"useTabs": true, | ||
"tabWidth": 4, | ||
"jsxBracketSameLine": false, | ||
"arrowParens": "avoid", | ||
"printWidth": 80 | ||
} | ||
} |
# 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. | ||
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. | ||
@@ -17,16 +17,14 @@ ## Usage | ||
}, | ||
plugins: { | ||
plugins: [ | ||
cssbundle() | ||
} | ||
] | ||
} | ||
``` | ||
## Options | ||
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 let you configure on which files the plugin should run. Additionally: | ||
__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 wherein to put the extracted CSS; when ommitted, we use the bundle's filename to fashion a name 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: | ||
```js | ||
@@ -33,0 +31,0 @@ // rollup.config.js |
@@ -5,11 +5,13 @@ import fs from 'fs-extra'; | ||
export default (opts) => { | ||
export default opts => { | ||
let styles = {}; | ||
let bundles = {}; | ||
const options = Object.assign({ | ||
include: ['**/*.css'], | ||
transform: code => code | ||
}, opts); | ||
const options = Object.assign( | ||
{ | ||
include: ['**/*.css'], | ||
transform: code => code | ||
}, | ||
opts | ||
); | ||
@@ -33,4 +35,10 @@ const filter = utils.createFilter(options.include, options.exclude); | ||
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) => bundle.modules.indexOf(a[0]) - bundle.modules.indexOf(b[0])) | ||
.sort((a, b) => modules.indexOf(a[0]) - modules.indexOf(b[0])) | ||
.map(entry => entry[1]) | ||
@@ -43,11 +51,12 @@ .join('\n'); | ||
fs.outputFile( | ||
options.output || | ||
path.join( | ||
path.dirname(opts.file), | ||
path.basename(opts.file, path.extname(opts.file)) + '.css' | ||
), | ||
options.output || | ||
path.join( | ||
path.dirname(opts.file), | ||
path.basename(opts.file, path.extname(opts.file)) + | ||
'.css' | ||
), | ||
bundles[opts.file] | ||
); | ||
} | ||
} | ||
} | ||
}; | ||
}; |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
6575
6
105
4
51