From c77b69de149e4f74256009b56997775097d3a48a Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Thu, 20 Sep 2018 17:50:30 +0100 Subject: [PATCH 1/5] Add ES-browser build This build is intended for users who want to use Redux in a browser with ES modules support. The build removes all references to `process` by assuming it is in a production environment. Additionally, it does not transpile, as all browsers that have ES modules support also support ES2015+ --- .gitignore | 1 + package.json | 3 ++- rollup.config.js | 27 ++++++++++++++++++++------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index a3ab034238..ac20efb643 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ node_modules dist lib es +es-browser coverage diff --git a/package.json b/package.json index 5e52a39896..0325339ed5 100644 --- a/package.json +++ b/package.json @@ -45,9 +45,10 @@ "test:cov": "npm test -- --coverage", "build:commonjs": "cross-env NODE_ENV=cjs rollup -c -o lib/redux.js", "build:es": "cross-env BABEL_ENV=es NODE_ENV=es rollup -c -o es/redux.js", + "build:es-browser": "cross-env BABEL_ENV=es NODE_ENV=es-browser rollup -c -o es-browser/redux.js", "build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -o dist/redux.js", "build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -o dist/redux.min.js", - "build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min", + "build": "npm run build:commonjs && npm run build:es && npm run build:es-browser && npm run build:umd && npm run build:umd:min", "prepare": "npm run clean && npm run format:check && npm run lint && npm test && npm run build", "examples:lint": "eslint examples", "examples:test": "cross-env CI=true babel-node examples/testAll.js" diff --git a/rollup.config.js b/rollup.config.js index d41f2499f9..0e563685e1 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,7 +3,8 @@ import babel from 'rollup-plugin-babel' import replace from 'rollup-plugin-replace' import { terser } from 'rollup-plugin-terser' -const env = process.env.NODE_ENV +const nodeEnv = process.env.NODE_ENV +const env = nodeEnv === 'es-browser' ? 'es' : nodeEnv; const config = { input: 'src/index.js', plugins: [] @@ -11,12 +12,24 @@ const config = { if (env === 'es' || env === 'cjs') { config.output = { format: env, indent: false } - config.external = ['symbol-observable'] - config.plugins.push( - babel({ - plugins: ['external-helpers'], - }) - ) + + if (nodeEnv === 'es-browser') { + config.plugins.push( + replace({ + 'process.env.NODE_ENV': '"production"' + }), + nodeResolve({ + jsnext: true + }) + ) + } else { + config.external = ['symbol-observable'] + config.plugins.push( + babel({ + plugins: ['external-helpers'], + }) + ) + } } if (env === 'development' || env === 'production') { From e8082350da157961a7897a609abd7b3aeac02cea Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Tue, 25 Sep 2018 19:29:26 +0100 Subject: [PATCH 2/5] Build browser-compatible package in es folder --- .gitignore | 1 - package.json | 2 +- rollup.config.js | 38 +++++++++++++++++++------------------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index ac20efb643..a3ab034238 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ node_modules dist lib es -es-browser coverage diff --git a/package.json b/package.json index 0325339ed5..67941d1e06 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "test:cov": "npm test -- --coverage", "build:commonjs": "cross-env NODE_ENV=cjs rollup -c -o lib/redux.js", "build:es": "cross-env BABEL_ENV=es NODE_ENV=es rollup -c -o es/redux.js", - "build:es-browser": "cross-env BABEL_ENV=es NODE_ENV=es-browser rollup -c -o es-browser/redux.js", + "build:es-browser": "cross-env BABEL_ENV=es NODE_ENV=es-browser rollup -c -o es/redux.browser.mjs", "build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -o dist/redux.js", "build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -o dist/redux.min.js", "build": "npm run build:commonjs && npm run build:es && npm run build:es-browser && npm run build:umd && npm run build:umd:min", diff --git a/rollup.config.js b/rollup.config.js index 0e563685e1..3ae99898bf 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,8 +3,7 @@ import babel from 'rollup-plugin-babel' import replace from 'rollup-plugin-replace' import { terser } from 'rollup-plugin-terser' -const nodeEnv = process.env.NODE_ENV -const env = nodeEnv === 'es-browser' ? 'es' : nodeEnv; +const env = process.env.NODE_ENV const config = { input: 'src/index.js', plugins: [] @@ -13,23 +12,24 @@ const config = { if (env === 'es' || env === 'cjs') { config.output = { format: env, indent: false } - if (nodeEnv === 'es-browser') { - config.plugins.push( - replace({ - 'process.env.NODE_ENV': '"production"' - }), - nodeResolve({ - jsnext: true - }) - ) - } else { - config.external = ['symbol-observable'] - config.plugins.push( - babel({ - plugins: ['external-helpers'], - }) - ) - } + config.external = ['symbol-observable'] + config.plugins.push( + babel({ + plugins: ['external-helpers'], + }) + ) +} + +if (env === 'es-browser') { + config.output = { format: 'es', indent: false } + config.plugins.push( + replace({ + 'process.env.NODE_ENV': '"production"' + }), + nodeResolve({ + jsnext: true + }) + ) } if (env === 'development' || env === 'production') { From 4098b3a61bdb2ceab7c801700691f2a8e01c1a2c Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Tue, 25 Sep 2018 19:30:07 +0100 Subject: [PATCH 3/5] Remove unnecessary whitespace --- rollup.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/rollup.config.js b/rollup.config.js index 3ae99898bf..bef46680b9 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -11,7 +11,6 @@ const config = { if (env === 'es' || env === 'cjs') { config.output = { format: env, indent: false } - config.external = ['symbol-observable'] config.plugins.push( babel({ From 6261ef4700b8162dfeeef435c21085b9b2410acb Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Tue, 25 Sep 2018 19:47:40 +0100 Subject: [PATCH 4/5] Minify browser build --- rollup.config.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rollup.config.js b/rollup.config.js index cfb2d3081a..7a20018fcf 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -37,6 +37,14 @@ export default [ }), replace({ 'process.env.NODE_ENV': JSON.stringify('production') + }), + terser({ + compress: { + pure_getters: true, + unsafe: true, + unsafe_comps: true, + warnings: false + } }) ] }, From 7c22e5db8c05c2f142d6bae606bea0f12efc857c Mon Sep 17 00:00:00 2001 From: Tim Dorr Date: Tue, 25 Sep 2018 14:53:41 -0400 Subject: [PATCH 5/5] Rename to just redux.mjs --- rollup.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollup.config.js b/rollup.config.js index 7a20018fcf..06b683d6d7 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -30,7 +30,7 @@ export default [ }, { input: 'src/index.js', - output: { file: 'es/redux.browser.mjs', format: 'es', indent: false }, + output: { file: 'es/redux.mjs', format: 'es', indent: false }, plugins: [ nodeResolve({ jsnext: true