From 0b6d794effa9da5080bfb4c6865a324357b85018 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Fri, 3 Nov 2017 20:18:28 +0300 Subject: [PATCH] Bundle cjs and es formats (#2358) * Bundle cjs and es formats * Test generated bundle * Missed a yarn command in the merge process * Updates to the rollup config. --- package.json | 13 +++++++------ rollup.config.js | 31 +++++++++++++++++++++++-------- 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 ++++++------ 7 files changed, 40 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index ff4a15e8ff..a77ef67f8c 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", @@ -15,13 +15,14 @@ "scripts": { "clean": "rimraf lib dist es coverage", "lint": "eslint src test build", + "pretest": "npm run build:commonjs", "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..659d6733d8 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,13 +3,28 @@ 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 = { - output: { - format: 'umd', - name: 'Redux' - }, - plugins: [ +const env = process.env.NODE_ENV +const config = { + input: 'src/index.js', + plugins: [] +} + +if (env === 'es' || env === 'cjs') { + config.output = { format: env } + config.external = [ + 'lodash/isPlainObject', + 'lodash-es/isPlainObject', + 'symbol-observable' + ]; + config.plugins.push( + babel() + ) +} + +if (env === 'development' || env === 'production') { + config.output = { format: 'umd' } + config.name = 'Redux' + config.plugins.push( nodeResolve({ jsnext: true }), @@ -19,7 +34,7 @@ var config = { replace({ 'process.env.NODE_ENV': JSON.stringify(env) }) - ] + ) } if (env === 'production') { 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'