Skip to content

Commit ca4d3d2

Browse files
TrySoundtomipaul
authored andcommitted
Bundle cjs and es formats (reduxjs#2358)
* Bundle cjs and es formats * Test generated bundle * Missed a yarn command in the merge process * Updates to the rollup config.
1 parent 6f3f3e4 commit ca4d3d2

7 files changed

+40
-25
lines changed

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "redux",
33
"version": "3.7.2",
44
"description": "Predictable state container for JavaScript apps",
5-
"main": "lib/index.js",
6-
"module": "es/index.js",
5+
"main": "lib/redux.js",
6+
"module": "es/redux.js",
77
"typings": "./index.d.ts",
88
"files": [
99
"dist",
@@ -15,13 +15,14 @@
1515
"scripts": {
1616
"clean": "rimraf lib dist es coverage",
1717
"lint": "eslint src test build",
18+
"pretest": "npm run build:commonjs",
1819
"test": "cross-env BABEL_ENV=commonjs jest",
1920
"test:watch": "npm test -- --watch",
2021
"test:cov": "npm test -- --coverage",
21-
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
22-
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",
23-
"build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -i src/index.js -o dist/redux.js",
24-
"build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -i src/index.js -o dist/redux.min.js",
22+
"build:commonjs": "cross-env NODE_ENV=cjs rollup -c -o lib/redux.js",
23+
"build:es": "cross-env BABEL_ENV=es NODE_ENV=es rollup -c -o es/redux.js",
24+
"build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -o dist/redux.js",
25+
"build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -o dist/redux.min.js",
2526
"build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
2627
"prepare": "npm run clean && npm run lint && npm test && npm run build",
2728
"examples:lint": "eslint examples",

rollup.config.js

+23-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,28 @@ import babel from 'rollup-plugin-babel'
33
import replace from 'rollup-plugin-replace'
44
import uglify from 'rollup-plugin-uglify'
55

6-
var env = process.env.NODE_ENV
7-
var config = {
8-
output: {
9-
format: 'umd',
10-
name: 'Redux'
11-
},
12-
plugins: [
6+
const env = process.env.NODE_ENV
7+
const config = {
8+
input: 'src/index.js',
9+
plugins: []
10+
}
11+
12+
if (env === 'es' || env === 'cjs') {
13+
config.output = { format: env }
14+
config.external = [
15+
'lodash/isPlainObject',
16+
'lodash-es/isPlainObject',
17+
'symbol-observable'
18+
];
19+
config.plugins.push(
20+
babel()
21+
)
22+
}
23+
24+
if (env === 'development' || env === 'production') {
25+
config.output = { format: 'umd' }
26+
config.name = 'Redux'
27+
config.plugins.push(
1328
nodeResolve({
1429
jsnext: true
1530
}),
@@ -19,7 +34,7 @@ var config = {
1934
replace({
2035
'process.env.NODE_ENV': JSON.stringify(env)
2136
})
22-
]
37+
)
2338
}
2439

2540
if (env === 'production') {

test/applyMiddleware.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createStore, applyMiddleware } from '../src/index'
1+
import { createStore, applyMiddleware } from '../'
22
import * as reducers from './helpers/reducers'
33
import { addTodo, addTodoAsync, addTodoIfEmpty } from './helpers/actionCreators'
44
import { thunk } from './helpers/middleware'

test/bindActionCreators.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bindActionCreators, createStore } from '../src'
1+
import { bindActionCreators, createStore } from '../'
22
import { todos } from './helpers/reducers'
33
import * as actionCreators from './helpers/actionCreators'
44

test/combineReducers.spec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable no-console */
2-
import { combineReducers } from '../src'
3-
import createStore from '../src/createStore'
2+
import { createStore, combineReducers } from '../'
43
import ActionTypes from '../src/utils/actionTypes'
54

65
describe('Utils', () => {

test/compose.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { compose } from '../src'
1+
import { compose } from '../'
22

33
describe('Utils', () => {
44
describe('compose', () => {

test/createStore.spec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { createStore, combineReducers } from '../src/index'
2-
import {
3-
addTodo,
4-
dispatchInMiddle,
1+
import { createStore, combineReducers } from '../'
2+
import {
3+
addTodo,
4+
dispatchInMiddle,
55
getStateInMiddle,
66
subscribeInMiddle,
77
unsubscribeInMiddle,
8-
throwError,
9-
unknownAction
8+
throwError,
9+
unknownAction
1010
} from './helpers/actionCreators'
1111
import * as reducers from './helpers/reducers'
1212
import * as Rx from 'rxjs'

0 commit comments

Comments
 (0)