Skip to content

Commit fd83904

Browse files
committed
build with rollup
1 parent ea5b9d0 commit fd83904

7 files changed

+5263
-49
lines changed

.size-snapshot.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"index.js": {
3+
"bundled": 4098,
4+
"minified": 2301,
5+
"gzipped": 978
6+
}
7+
}

babel.config.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = (api, targets) => {
2+
// https://babeljs.io/docs/en/config-files#config-function-api
3+
const isTestEnv = api.env('test')
4+
5+
return {
6+
babelrc: false,
7+
ignore: ['./node_modules'],
8+
presets: [
9+
[
10+
'@babel/preset-env',
11+
{
12+
loose: true,
13+
modules: isTestEnv ? 'commonjs' : false,
14+
targets: isTestEnv ? { node: 'current' } : targets,
15+
},
16+
],
17+
],
18+
}
19+
}

package.json

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "index.js",
77
"scripts": {
88
"prebuild": "shx rm -rf dist",
9-
"build": "shx mkdir dist && shx cp lib/*.js dist",
9+
"build": "rollup -c",
1010
"postbuild": "yarn copy",
1111
"test": "node tests/index.js",
1212
"copy": "copyfiles -f package.json README.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.husky=undefined; this.prettier=undefined; this.jest=undefined; this['lint-staged']=undefined;\""
@@ -44,15 +44,24 @@
4444
},
4545
"homepage": "https://github.com/pmndrs/eslint-plugin-valtio",
4646
"devDependencies": {
47+
"@babel/core": "^7.12.10",
48+
"@babel/preset-env": "^7.12.11",
49+
"@rollup/plugin-babel": "^5.2.2",
50+
"@rollup/plugin-node-resolve": "^11.0.1",
51+
"copyfiles": "^2.4.1",
4752
"eslint": "^7.1.0",
48-
"husky": "^4.3.6",
49-
"lint-staged": "^10.5.3",
50-
"prettier": "^2.2.1",
5153
"eslint-config-prettier": "^7.1.0",
5254
"eslint-import-resolver-alias": "^1.1.2",
5355
"eslint-plugin-import": "^2.22.1",
5456
"eslint-plugin-jest": "^24.1.3",
5557
"eslint-plugin-prettier": "^3.3.0" ,
58+
"husky": "^4.3.6",
59+
"jest": "^26.6.3",
60+
"json": "^10.0.0",
61+
"lint-staged": "^10.5.3",
62+
"prettier": "^2.2.1",
63+
"rollup": "^2.35.1",
64+
"rollup-plugin-size-snapshot": "^0.12.0",
5665
"shx": "^0.3.3"
5766
}
5867
}

rollup.config.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import path from 'path'
2+
import babel from '@rollup/plugin-babel'
3+
import resolve from '@rollup/plugin-node-resolve'
4+
import { sizeSnapshot } from 'rollup-plugin-size-snapshot'
5+
6+
const createBabelConfig = require('./babel.config')
7+
8+
const { root } = path.parse(process.cwd())
9+
const external = (id) => !id.startsWith('.') && !id.startsWith(root)
10+
const extensions = ['.js', '.ts', '.tsx']
11+
const getBabelOptions = (targets) => ({
12+
...createBabelConfig({ env: (env) => env === 'build' }, targets),
13+
extensions,
14+
})
15+
16+
function createCommonJSConfig(input, output) {
17+
return {
18+
input,
19+
output: { file: output, format: 'cjs', exports: 'named' },
20+
external,
21+
plugins: [
22+
resolve({ extensions }),
23+
babel(getBabelOptions({ ie: 11 })),
24+
sizeSnapshot(),
25+
],
26+
}
27+
}
28+
29+
export default [createCommonJSConfig('src/index.js', 'dist/index.js')]
File renamed without changes.

lib/index.js src/index.js

File renamed without changes.

0 commit comments

Comments
 (0)