Skip to content

Commit 9cd9662

Browse files
authored
support build of es modules (#570)
1 parent d0c7891 commit 9cd9662

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Diff for: package.json

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
"build": "yarn lint && rollup -c && yarn test:build",
3636
"build:ci": "rollup -c && yarn test:build",
3737
"build:web": "yarn lint && rollup -c rollup.config.web.js && yarn test:build:web",
38+
"build:esm": "yarn lint && rollup -c rollup.config.esm.js && yarn test:build:esm",
39+
"build:esm:ci": "rollup -c rollup.config.esm.js && yarn test:build:esm",
3840
"build:web:ci": "rollup -c rollup.config.web.js && yarn test:build:web",
3941
"release": "yarn build && yarn build:web",
4042
"build:generator": "rollup -c scripts/rollup.config.js",
@@ -44,6 +46,7 @@
4446
"test:web": "node ./node_modules/karma/bin/karma start karma.conf.js --auto-watch",
4547
"test:build": "cd ./scripts && jest check-build.test.js",
4648
"test:build:web": "node ./scripts/proxy-browser-test.js",
49+
"test:build:esm": "node ./scripts/proxy-browser-test.js",
4750
"watch:test": "jest --watch",
4851
"generate-parser": "node ./dist/generate-custom-parser.js"
4952
},
@@ -104,6 +107,7 @@
104107
"rollup-plugin-commonjs": "^9.2.0",
105108
"rollup-plugin-node-globals": "^1.4.0",
106109
"rollup-plugin-node-resolve": "^2.0.0",
110+
"rollup-plugin-terser": "^6.1.0",
107111
"rollup-plugin-uglify": "^6.0.1",
108112
"watchify": "^3.11.1"
109113
},

Diff for: rollup.config.esm.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import nodeResolve from 'rollup-plugin-node-resolve';
2+
import globals from 'rollup-plugin-node-globals';
3+
import { terser } from 'rollup-plugin-terser'; // eslint-disable-line import/extensions
4+
import babel from 'rollup-plugin-babel';
5+
import commonjs from 'rollup-plugin-commonjs';
6+
7+
export default {
8+
input: 'src/mercury.js',
9+
plugins: [
10+
babel({
11+
runtimeHelpers: true,
12+
exclude: './node_modules#<{(|*',
13+
}),
14+
commonjs({
15+
ignoreGlobal: true,
16+
}),
17+
globals(),
18+
nodeResolve({
19+
browser: true,
20+
preferBuiltins: false,
21+
}),
22+
terser(),
23+
],
24+
treeshake: true,
25+
output: {
26+
file: process.env.MERCURY_TEST_BUILD
27+
? 'dist/mercury_test.esm.js'
28+
: 'dist/mercury.esm.js',
29+
format: 'es',
30+
sourceMap: true,
31+
},
32+
};

0 commit comments

Comments
 (0)