Skip to content

Commit ece6892

Browse files
TrySoundseantcoyote
authored andcommitted
Build umd with rollup (reduxjs#2283)
* Build umd with rollup * Resolve jsnext entry in symbol-observable * Remove useless commonjs * Don't try to handle a missing process.env
1 parent 8a9a2ea commit ece6892

File tree

5 files changed

+129
-401
lines changed

5 files changed

+129
-401
lines changed

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"test:cov": "yarn test -- --coverage",
2323
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
2424
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",
25-
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack src/index.js dist/redux.js",
26-
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack src/index.js dist/redux.min.js",
25+
"build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -i src/index.js -o dist/redux.js",
26+
"build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -i src/index.js -o dist/redux.min.js",
2727
"build": "yarn run build:commonjs && yarn run build:es && yarn run build:umd && yarn run build:umd:min",
2828
"prepublish": "yarn run clean && yarn run lint && yarn test && yarn run build && check-es3-syntax lib/ dist/ --kill --print",
2929
"examples:build": "babel-node examples/buildAll.js",
@@ -72,7 +72,6 @@
7272
"babel-core": "^6.3.15",
7373
"babel-eslint": "^7.0.0",
7474
"babel-jest": "^18.0.0",
75-
"babel-loader": "^6.2.0",
7675
"babel-plugin-check-es2015-constants": "^6.3.13",
7776
"babel-plugin-transform-es2015-arrow-functions": "^6.3.13",
7877
"babel-plugin-transform-es2015-block-scoped-functions": "^6.3.13",
@@ -107,10 +106,14 @@
107106
"glob": "^7.1.1",
108107
"jest": "^18.0.0",
109108
"rimraf": "^2.3.4",
109+
"rollup": "^0.41.4",
110+
"rollup-plugin-babel": "^2.7.1",
111+
"rollup-plugin-node-resolve": "^2.0.0",
112+
"rollup-plugin-replace": "^1.1.1",
113+
"rollup-plugin-uglify": "^1.0.1",
110114
"rxjs": "^5.0.0-beta.6",
111115
"typescript": "^1.8.0",
112-
"typescript-definition-tester": "0.0.4",
113-
"webpack": "^1.9.6"
116+
"typescript-definition-tester": "0.0.4"
114117
},
115118
"npmName": "redux",
116119
"npmFileMap": [
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
'use strict';
2-
3-
var webpack = require('webpack')
1+
import nodeResolve from 'rollup-plugin-node-resolve';
2+
import babel from 'rollup-plugin-babel';
3+
import replace from 'rollup-plugin-replace';
4+
import uglify from 'rollup-plugin-uglify';
45

56
var env = process.env.NODE_ENV
67
var config = {
7-
module: {
8-
loaders: [
9-
{ test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ }
10-
]
11-
},
12-
output: {
13-
library: 'Redux',
14-
libraryTarget: 'umd'
15-
},
8+
format: 'umd',
9+
moduleName: 'Redux',
1610
plugins: [
17-
new webpack.optimize.OccurrenceOrderPlugin(),
18-
new webpack.DefinePlugin({
11+
nodeResolve({
12+
jsnext: true
13+
}),
14+
babel({
15+
exclude: 'node_modules/**'
16+
}),
17+
replace({
1918
'process.env.NODE_ENV': JSON.stringify(env)
2019
})
2120
]
22-
};
21+
}
2322

2423
if (env === 'production') {
2524
config.plugins.push(
26-
new webpack.optimize.UglifyJsPlugin({
27-
compressor: {
25+
uglify({
26+
compress: {
2827
pure_getters: true,
2928
unsafe: true,
3029
unsafe_comps: true,
@@ -41,4 +40,4 @@ if (env === 'production') {
4140
)
4241
}
4342

44-
module.exports = config
43+
export default config

src/combineReducers.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { ActionTypes } from './createStore'
22
import isPlainObject from 'lodash/isPlainObject'
33
import warning from './utils/warning'
44

5-
const NODE_ENV = typeof process !== 'undefined' ? process.env.NODE_ENV : 'development'
6-
75
function getUndefinedStateErrorMessage(key, action) {
86
const actionType = action && action.type
97
const actionName = (actionType && `"${actionType.toString()}"`) || 'an action'
@@ -107,7 +105,7 @@ export default function combineReducers(reducers) {
107105
for (let i = 0; i < reducerKeys.length; i++) {
108106
const key = reducerKeys[i]
109107

110-
if (NODE_ENV !== 'production') {
108+
if (process.env.NODE_ENV !== 'production') {
111109
if (typeof reducers[key] === 'undefined') {
112110
warning(`No reducer provided for key "${key}"`)
113111
}
@@ -120,7 +118,7 @@ export default function combineReducers(reducers) {
120118
const finalReducerKeys = Object.keys(finalReducers)
121119

122120
let unexpectedKeyCache
123-
if (NODE_ENV !== 'production') {
121+
if (process.env.NODE_ENV !== 'production') {
124122
unexpectedKeyCache = {}
125123
}
126124

@@ -136,7 +134,7 @@ export default function combineReducers(reducers) {
136134
throw sanityError
137135
}
138136

139-
if (NODE_ENV !== 'production') {
137+
if (process.env.NODE_ENV !== 'production') {
140138
const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache)
141139
if (warningMessage) {
142140
warning(warningMessage)

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import warning from './utils/warning'
1212
function isCrushed() {}
1313

1414
if (
15-
typeof process !== 'undefined' &&
1615
process.env.NODE_ENV !== 'production' &&
1716
typeof isCrushed.name === 'string' &&
1817
isCrushed.name !== 'isCrushed'

0 commit comments

Comments
 (0)