From 708982d5ad2217c8a2302a08a64617c6575d8c49 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Thu, 13 Apr 2017 21:50:11 +0300 Subject: [PATCH 1/4] Bundle cjs and es formats --- package.json | 12 ++++++------ rollup.config.js | 27 +++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index ff4a15e8ff..4efd33c1d5 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "redux", "version": "3.7.2", "description": "Predictable state container for JavaScript apps", - "main": "lib/index.js", - "module": "es/index.js", + "main": "lib/redux.js", + "module": "es/redux.js", "typings": "./index.d.ts", "files": [ "dist", @@ -18,10 +18,10 @@ "test": "cross-env BABEL_ENV=commonjs jest", "test:watch": "npm test -- --watch", "test:cov": "npm test -- --coverage", - "build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib", - "build:es": "cross-env BABEL_ENV=es babel src --out-dir es", - "build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -i src/index.js -o dist/redux.js", - "build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -i src/index.js -o dist/redux.min.js", + "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: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", "prepare": "npm run clean && npm run lint && npm test && npm run build", "examples:lint": "eslint examples", diff --git a/rollup.config.js b/rollup.config.js index 6c7aedde85..3df00e43bb 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,13 +3,32 @@ import babel from 'rollup-plugin-babel' import replace from 'rollup-plugin-replace' import uglify from 'rollup-plugin-uglify' -var env = process.env.NODE_ENV -var config = { +const env = process.env.NODE_ENV +const config = { output: { format: 'umd', name: 'Redux' }, - plugins: [ + entry: 'src/index.js', + plugins: [] +} + +if (env === 'es' || env === 'cjs') { + config.format = env + config.external = [ + 'lodash/isPlainObject', + 'lodash-es/isPlainObject', + 'symbol-observable' + ]; + config.plugins.push( + babel() + ) +} + +if (env === 'development' || env === 'production') { + config.format = 'umd' + config.moduleName = 'Redux' + config.plugins.push( nodeResolve({ jsnext: true }), @@ -19,7 +38,7 @@ var config = { replace({ 'process.env.NODE_ENV': JSON.stringify(env) }) - ] + ) } if (env === 'production') { From 4d20bbfcb0d4ac37d97c119b5d34525bdb5e377b Mon Sep 17 00:00:00 2001 From: TrySound Date: Fri, 14 Apr 2017 15:42:06 +0300 Subject: [PATCH 2/4] Test generated bundle --- package.json | 1 + test/applyMiddleware.spec.js | 2 +- test/bindActionCreators.spec.js | 2 +- test/combineReducers.spec.js | 3 +-- test/compose.spec.js | 2 +- test/createStore.spec.js | 12 ++++++------ 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 4efd33c1d5..f0fa287e36 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "scripts": { "clean": "rimraf lib dist es coverage", "lint": "eslint src test build", + "pretest": "yarn run build:commonjs", "test": "cross-env BABEL_ENV=commonjs jest", "test:watch": "npm test -- --watch", "test:cov": "npm test -- --coverage", diff --git a/test/applyMiddleware.spec.js b/test/applyMiddleware.spec.js index 5968c497c3..fef3121c5d 100644 --- a/test/applyMiddleware.spec.js +++ b/test/applyMiddleware.spec.js @@ -1,4 +1,4 @@ -import { createStore, applyMiddleware } from '../src/index' +import { createStore, applyMiddleware } from '../' import * as reducers from './helpers/reducers' import { addTodo, addTodoAsync, addTodoIfEmpty } from './helpers/actionCreators' import { thunk } from './helpers/middleware' diff --git a/test/bindActionCreators.spec.js b/test/bindActionCreators.spec.js index 7c8a517c96..e773776268 100644 --- a/test/bindActionCreators.spec.js +++ b/test/bindActionCreators.spec.js @@ -1,4 +1,4 @@ -import { bindActionCreators, createStore } from '../src' +import { bindActionCreators, createStore } from '../' import { todos } from './helpers/reducers' import * as actionCreators from './helpers/actionCreators' diff --git a/test/combineReducers.spec.js b/test/combineReducers.spec.js index b722a151a1..c23db998b4 100644 --- a/test/combineReducers.spec.js +++ b/test/combineReducers.spec.js @@ -1,6 +1,5 @@ /* eslint-disable no-console */ -import { combineReducers } from '../src' -import createStore from '../src/createStore' +import { createStore, combineReducers } from '../' import ActionTypes from '../src/utils/actionTypes' describe('Utils', () => { diff --git a/test/compose.spec.js b/test/compose.spec.js index 67974bbd23..de0343adda 100644 --- a/test/compose.spec.js +++ b/test/compose.spec.js @@ -1,4 +1,4 @@ -import { compose } from '../src' +import { compose } from '../' describe('Utils', () => { describe('compose', () => { diff --git a/test/createStore.spec.js b/test/createStore.spec.js index 3ca7197e27..62d209fc79 100644 --- a/test/createStore.spec.js +++ b/test/createStore.spec.js @@ -1,12 +1,12 @@ -import { createStore, combineReducers } from '../src/index' -import { - addTodo, - dispatchInMiddle, +import { createStore, combineReducers } from '../' +import { + addTodo, + dispatchInMiddle, getStateInMiddle, subscribeInMiddle, unsubscribeInMiddle, - throwError, - unknownAction + throwError, + unknownAction } from './helpers/actionCreators' import * as reducers from './helpers/reducers' import * as Rx from 'rxjs' From ae00949d2c148f70ee8172637f416886c6331cc3 Mon Sep 17 00:00:00 2001 From: Tim Dorr Date: Fri, 3 Nov 2017 12:49:25 -0400 Subject: [PATCH 3/4] Missed a yarn command in the merge process --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f0fa287e36..a77ef67f8c 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "scripts": { "clean": "rimraf lib dist es coverage", "lint": "eslint src test build", - "pretest": "yarn run build:commonjs", + "pretest": "npm run build:commonjs", "test": "cross-env BABEL_ENV=commonjs jest", "test:watch": "npm test -- --watch", "test:cov": "npm test -- --coverage", From 5e06fecb707738873f04f2a9b21babc1a0fc0190 Mon Sep 17 00:00:00 2001 From: Tim Dorr Date: Fri, 3 Nov 2017 12:59:49 -0400 Subject: [PATCH 4/4] Updates to the rollup config. --- rollup.config.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 3df00e43bb..659d6733d8 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -5,16 +5,12 @@ import uglify from 'rollup-plugin-uglify' const env = process.env.NODE_ENV const config = { - output: { - format: 'umd', - name: 'Redux' - }, - entry: 'src/index.js', + input: 'src/index.js', plugins: [] } if (env === 'es' || env === 'cjs') { - config.format = env + config.output = { format: env } config.external = [ 'lodash/isPlainObject', 'lodash-es/isPlainObject', @@ -26,8 +22,8 @@ if (env === 'es' || env === 'cjs') { } if (env === 'development' || env === 'production') { - config.format = 'umd' - config.moduleName = 'Redux' + config.output = { format: 'umd' } + config.name = 'Redux' config.plugins.push( nodeResolve({ jsnext: true