Skip to content

Commit e791432

Browse files
committed
feat: native Node.js ES Modules (isolated state approach)
See: https://nodejs.org/docs/latest-v12.x/api/esm.html#esm_dual_commonjs_es_module_packages
1 parent f67b17a commit e791432

12 files changed

+245
-31
lines changed

.local/wrapper.mjs

-1
This file was deleted.

bundlewatch.config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"files": [
3-
{ "path": "./examples/browser-rollup/dist/v1-size.js", "maxSize": "0.8 kB" },
3+
{ "path": "./examples/browser-rollup/dist/v1-size.js", "maxSize": "0.9 kB" },
44
{ "path": "./examples/browser-rollup/dist/v3-size.js", "maxSize": "1.8 kB" },
55
{ "path": "./examples/browser-rollup/dist/v4-size.js", "maxSize": "0.5 kB" },
66
{ "path": "./examples/browser-rollup/dist/v5-size.js", "maxSize": "1.2 kB" },

examples/browser-rollup/package-lock.json

+141
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/browser-rollup/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"uuid": "file:../../.local"
1111
},
1212
"devDependencies": {
13+
"@rollup/plugin-commonjs": "^11.1.0",
1314
"@rollup/plugin-node-resolve": "^7.1.3",
1415
"rollup": "^2.6.1",
1516
"rollup-plugin-terser": "^5.3.0"

examples/browser-rollup/rollup.config.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
const commonjs = require('@rollup/plugin-commonjs');
12
const resolve = require('@rollup/plugin-node-resolve');
23
const { terser } = require('rollup-plugin-terser');
34

4-
const plugins = [resolve({ browser: true }), terser()];
5+
const plugins = [
6+
resolve({ browser: true }),
7+
commonjs({
8+
extensions: ['.cjs'],
9+
}),
10+
terser(),
11+
];
512
module.exports = [
613
{
714
input: './example-all.js',

package-lock.json

+53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
"main": "./dist/index.js",
2121
"exports": {
2222
"require": "./dist/index.js",
23-
"import": "./wrapper.mjs"
23+
"import": "./dist/esm-node/index.mjs"
2424
},
25-
"module": "./dist/esm-node/index.js",
25+
"module": "./dist/esm-node/index.mjs",
2626
"browser": {
2727
"./dist/md5.js": "./dist/md5-browser.js",
2828
"./dist/rng.js": "./dist/rng-browser.js",
2929
"./dist/sha1.js": "./dist/sha1-browser.js",
30-
"./dist/esm-node/index.js": "./dist/esm-browser/index.js"
30+
"./dist/esm-node/index.mjs": "./dist/esm-browser/index.js"
3131
},
3232
"files": [
3333
"CHANGELOG.md",
@@ -39,15 +39,15 @@
3939
"v1.js",
4040
"v3.js",
4141
"v4.js",
42-
"v5.js",
43-
"wrapper.mjs"
42+
"v5.js"
4443
],
4544
"devDependencies": {
4645
"@babel/cli": "7.8.4",
4746
"@babel/core": "7.9.0",
4847
"@babel/preset-env": "7.9.5",
4948
"@commitlint/cli": "8.3.5",
5049
"@commitlint/config-conventional": "8.3.4",
50+
"@rollup/plugin-commonjs": "11.1.0",
5151
"@rollup/plugin-node-resolve": "7.1.3",
5252
"@wdio/browserstack-service": "6.0.12",
5353
"@wdio/cli": "6.0.15",

rollup.config.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import nodeResolve from '@rollup/plugin-node-resolve';
2+
import commonjs from '@rollup/plugin-commonjs';
23
import { terser } from 'rollup-plugin-terser';
34

45
function chunk(input, name) {
@@ -10,7 +11,13 @@ function chunk(input, name) {
1011
name,
1112
compact: true,
1213
},
13-
plugins: [nodeResolve({ browser: true }), terser()],
14+
plugins: [
15+
nodeResolve({ browser: true }),
16+
commonjs({
17+
extensions: ['.cjs'],
18+
}),
19+
terser(),
20+
],
1421
};
1522
}
1623

0 commit comments

Comments
 (0)