Skip to content

Commit 47751b8

Browse files
committed
Housekeeping:
- added prettier / pretty-quick / husky pre-commit hook - upgraded to latest version of Rollup for the build process - added Changelog
1 parent e96a462 commit 47751b8

File tree

5 files changed

+597
-50
lines changed

5 files changed

+597
-50
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
#### Unreleased
4+
5+
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)!)

package.json

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
11
{
2-
"name": "rollup-plugin-css-bundle",
3-
"version": "1.0.2",
4-
"main": "dist/index.js",
5-
"module": "src/index.js",
6-
"repository": "git@github.com:danburzo/rollup-plugin-css-bundle.git",
7-
"author": "Dan Burzo <danburzo@gmail.com>",
8-
"keywords": [
9-
"rollup-plugin"
10-
],
11-
"license": "MIT",
12-
"files": [
13-
"src",
14-
"dist"
15-
],
16-
"devDependencies": {
17-
"rollup": "^0.58.1"
18-
},
19-
"dependencies": {
20-
"fs-extra": "^5.0.0",
21-
"rollup-pluginutils": "^2.0.1"
22-
},
23-
"scripts": {
24-
"build": "rollup -c",
25-
"watch": "rollup -w -c"
26-
}
2+
"name": "rollup-plugin-css-bundle",
3+
"version": "1.0.2",
4+
"description": "A Rollup plugin to extract CSS into a single external file",
5+
"main": "dist/index.js",
6+
"module": "src/index.js",
7+
"repository": "Evercoder/rollup-plugin-css-bundle",
8+
"author": "Dan Burzo <danburzo@gmail.com>",
9+
"keywords": [
10+
"rollup-plugin",
11+
"css"
12+
],
13+
"license": "MIT",
14+
"files": [
15+
"src",
16+
"dist"
17+
],
18+
"devDependencies": {
19+
"husky": "^1.1.2",
20+
"prettier": "1.14.3",
21+
"pretty-quick": "^1.8.0",
22+
"rollup": "^0.66.6"
23+
},
24+
"dependencies": {
25+
"fs-extra": "^5.0.0",
26+
"rollup-pluginutils": "^2.0.1"
27+
},
28+
"scripts": {
29+
"build": "rollup -c",
30+
"watch": "rollup -w -c",
31+
"release": "yarn build && yarn publish"
32+
},
33+
"husky": {
34+
"hooks": {
35+
"pre-commit": "pretty-quick --staged"
36+
}
37+
},
38+
"prettier": {
39+
"bracketSpacing": true,
40+
"semi": true,
41+
"singleQuote": true,
42+
"trailingComma": "none",
43+
"useTabs": true,
44+
"tabWidth": 4,
45+
"jsxBracketSameLine": false,
46+
"arrowParens": "avoid",
47+
"printWidth": 80
48+
}
2749
}

rollup.config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import pkg from './package.json';
22

33
export default {
44
input: 'src/index.js',
5+
external: Object.keys(pkg.dependencies).concat(
6+
// Node standard modules
7+
['path']
8+
),
59
output: {
610
format: 'cjs',
7-
file: pkg.main,
8-
external: Object.keys(pkg.dependencies)
11+
file: pkg.main
912
}
10-
}
13+
};

src/index.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ import fs from 'fs-extra';
22
import path from 'path';
33
import utils from 'rollup-pluginutils';
44

5-
export default (opts) => {
6-
5+
export default opts => {
76
let styles = {};
87
let bundles = {};
98

10-
const options = Object.assign({
11-
include: ['**/*.css'],
12-
transform: code => code
13-
}, opts);
9+
const options = Object.assign(
10+
{
11+
include: ['**/*.css'],
12+
transform: code => code
13+
},
14+
opts
15+
);
1416

1517
const filter = utils.createFilter(options.include, options.exclude);
1618

@@ -29,8 +31,12 @@ export default (opts) => {
2931
},
3032

3133
ongenerate(opts, bundle) {
32-
let modules = Array.isArray(bundle.modules) ? bundle.modules
33-
: Object.getOwnPropertyNames(bundle.modules)
34+
// Depending on the Rollup version,
35+
// the `modules` will be either an array
36+
// or an object with key-value pairs.
37+
let modules = Array.isArray(bundle.modules)
38+
? bundle.modules
39+
: Object.getOwnPropertyNames(bundle.modules);
3440
let css = Object.entries(styles)
3541
.sort((a, b) => modules.indexOf(a[0]) - modules.indexOf(b[0]))
3642
.map(entry => entry[1])
@@ -40,13 +46,14 @@ export default (opts) => {
4046

4147
onwrite(opts) {
4248
fs.outputFile(
43-
options.output ||
44-
path.join(
45-
path.dirname(opts.file),
46-
path.basename(opts.file, path.extname(opts.file)) + '.css'
47-
),
49+
options.output ||
50+
path.join(
51+
path.dirname(opts.file),
52+
path.basename(opts.file, path.extname(opts.file)) +
53+
'.css'
54+
),
4855
bundles[opts.file]
4956
);
5057
}
51-
}
52-
}
58+
};
59+
};

0 commit comments

Comments
 (0)