Skip to content

Commit 574f89e

Browse files
authored
Merge pull request #67 from cssinjs/rollup
Build bundles with rollup
2 parents 0429206 + aab07dd commit 574f89e

7 files changed

+696
-27
lines changed

.size-snapshot.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"dist/css-vendor.js": {
3+
"bundled": 15626,
4+
"minified": 4984,
5+
"gzipped": 1907
6+
},
7+
"dist/css-vendor.min.js": {
8+
"bundled": 15626,
9+
"minified": 4984,
10+
"gzipped": 1907
11+
},
12+
"./lib/index": {
13+
"bundled": 14406,
14+
"minified": 6274,
15+
"gzipped": 2186
16+
},
17+
"./dist/css-vendor.cjs.js": {
18+
"bundled": 13753,
19+
"minified": 5745,
20+
"gzipped": 1985
21+
},
22+
"./dist/css-vendor.esm.js": {
23+
"bundled": 13434,
24+
"minified": 5484,
25+
"gzipped": 1894,
26+
"treeshaked": {
27+
"rollup": {
28+
"code": 3041,
29+
"import_statements": 89
30+
},
31+
"webpack": {
32+
"code": 4192
33+
}
34+
}
35+
}
36+
}

babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = (api) => {
22
api.cache(true)
3-
const presets = ['@babel/env']
3+
const presets = [['@babel/env', {loose: true}]]
44
const plugins = [
55
'transform-es2015-spread',
66
'transform-es3-member-expression-literals',

package.json

+16-12
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
"css-in-js"
2222
],
2323
"engines": {},
24+
"main": "./dist/css-vendor.cjs.js",
25+
"module": "./dist/css-vendor.esm.js",
26+
"files": [
27+
"dist"
28+
],
2429
"scripts": {
2530
"all": "yarn lint && yarn test && yarn build",
26-
"build": "yarn clean && yarn build:lib && yarn build:dist",
27-
"build:lib": "babel src --out-dir lib",
28-
"build:dist": "yarn build:dist:max && yarn build:dist:min",
29-
"build:dist:max": "cross-env webpack --mode=development src/index.js --output-filename=css-vendor.js",
30-
"build:dist:min": "cross-env webpack --mode=production src/index.js --output-filename=css-vendor.min.js",
31-
"clean": "rimraf {lib,dist,tmp}/*",
31+
"build": "yarn clean && yarn rollup -c",
32+
"clean": "rimraf {dist,tmp}/*",
3233
"lint": "eslint ./src ./tests --fix",
3334
"lint:staged": "lint-staged",
3435
"test": "cross-env NODE_ENV=test karma start --single-run ",
@@ -37,9 +38,9 @@
3738
"prepublishOnly": "yarn all"
3839
},
3940
"license": "MIT",
40-
"main": "./lib/index",
4141
"devDependencies": {
4242
"@babel/core": "^7.2.2",
43+
"@babel/plugin-transform-runtime": "^7.2.0",
4344
"@babel/preset-env": "^7.2.3",
4445
"autoprefixer": "^9.3.1",
4546
"babel-cli": "^6.5.1",
@@ -76,10 +77,17 @@
7677
"postcss-js": "^2.0.0",
7778
"pre-commit": "^1.1.3",
7879
"rimraf": "^2.6.2",
80+
"rollup": "^1.1.2",
81+
"rollup-plugin-babel": "^4.3.2",
82+
"rollup-plugin-node-resolve": "^4.0.0",
83+
"rollup-plugin-replace": "^2.1.0",
84+
"rollup-plugin-size-snapshot": "^0.8.0",
85+
"rollup-plugin-terser": "^4.0.3",
7986
"webpack": "^4.15.1",
8087
"webpack-cli": "^3.0.8"
8188
},
8289
"dependencies": {
90+
"@babel/runtime": "^7.3.1",
8391
"is-in-browser": "^1.0.2"
8492
},
8593
"lint-staged": {
@@ -88,9 +96,5 @@
8896
"git add"
8997
]
9098
},
91-
"pre-commit": "lint:staged",
92-
"files": [
93-
"dist",
94-
"lib"
95-
]
99+
"pre-commit": "lint:staged"
96100
}

rollup.config.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import nodeResolve from 'rollup-plugin-node-resolve'
2+
import babel from 'rollup-plugin-babel'
3+
import replace from 'rollup-plugin-replace'
4+
import {terser} from 'rollup-plugin-terser'
5+
import {sizeSnapshot} from 'rollup-plugin-size-snapshot'
6+
import pkg from './package.json'
7+
8+
const input = './src/index.js'
9+
10+
const name = 'cssVendor'
11+
12+
const external = id => !id.startsWith('.') && !id.startsWith('/')
13+
14+
const getBabelOptions = ({useESModules}) => ({
15+
exclude: /node_modules/,
16+
runtimeHelpers: true,
17+
plugins: [
18+
['@babel/transform-runtime', {useESModules}]
19+
]
20+
})
21+
22+
export default [
23+
{
24+
input,
25+
output: {file: `dist/${pkg.name}.js`, format: 'umd', name},
26+
plugins: [
27+
nodeResolve(),
28+
babel(getBabelOptions({useESModules: true})),
29+
replace({'process.env.NODE_ENV': JSON.stringify('development')}),
30+
sizeSnapshot()
31+
]
32+
},
33+
34+
{
35+
input,
36+
output: {file: `dist/${pkg.name}.min.js`, format: 'umd', name},
37+
plugins: [
38+
nodeResolve(),
39+
babel(getBabelOptions({useESModules: true})),
40+
replace({'process.env.NODE_ENV': JSON.stringify('production')}),
41+
sizeSnapshot(),
42+
terser()
43+
]
44+
},
45+
46+
{
47+
input,
48+
output: {file: pkg.main, format: 'cjs'},
49+
external,
50+
plugins: [
51+
babel(getBabelOptions({useESModules: false})),
52+
sizeSnapshot()
53+
]
54+
},
55+
56+
{
57+
input,
58+
output: {file: pkg.module, format: 'esm'},
59+
external,
60+
plugins: [
61+
babel(getBabelOptions({useESModules: true})),
62+
sizeSnapshot()
63+
]
64+
},
65+
]

src/index.js

-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ import supportedKeyframes from './supported-keyframes'
1111
import supportedProperty from './supported-property'
1212
import supportedValue from './supported-value'
1313

14-
export default {
15-
prefix,
16-
supportedKeyframes,
17-
supportedProperty,
18-
supportedValue
19-
}
20-
2114
export {
2215
prefix,
2316
supportedKeyframes,

src/supported-property.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import isInBrowser from 'is-in-browser'
2-
import {propertyDetectors, noPrefill} from './plugins'
2+
import {propertyDetectors, noPrefill} from './plugins/index.js'
33

44
let el
55
const cache = {}

0 commit comments

Comments
 (0)