Skip to content

Commit

Permalink
Build umd with rollup (#2283)
Browse files Browse the repository at this point in the history
* Build umd with rollup

* Resolve jsnext entry in symbol-observable

* Remove useless commonjs

* Don't try to handle a missing process.env
  • Loading branch information
TrySound authored and timdorr committed Mar 8, 2017
1 parent 1b154e0 commit bf13473
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 401 deletions.
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"test:cov": "yarn 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=commonjs NODE_ENV=development webpack src/index.js dist/redux.js",
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack src/index.js dist/redux.min.js",
"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": "yarn run build:commonjs && yarn run build:es && yarn run build:umd && yarn run build:umd:min",
"prepublish": "yarn run clean && yarn run lint && yarn test && yarn run build && check-es3-syntax lib/ dist/ --kill --print",
"examples:build": "babel-node examples/buildAll.js",
Expand Down Expand Up @@ -72,7 +72,6 @@
"babel-core": "^6.3.15",
"babel-eslint": "^7.0.0",
"babel-jest": "^18.0.0",
"babel-loader": "^6.2.0",
"babel-plugin-check-es2015-constants": "^6.3.13",
"babel-plugin-transform-es2015-arrow-functions": "^6.3.13",
"babel-plugin-transform-es2015-block-scoped-functions": "^6.3.13",
Expand Down Expand Up @@ -107,10 +106,14 @@
"glob": "^7.1.1",
"jest": "^18.0.0",
"rimraf": "^2.3.4",
"rollup": "^0.41.4",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-replace": "^1.1.1",
"rollup-plugin-uglify": "^1.0.1",
"rxjs": "^5.0.0-beta.6",
"typescript": "^1.8.0",
"typescript-definition-tester": "0.0.4",
"webpack": "^1.9.6"
"typescript-definition-tester": "0.0.4"
},
"npmName": "redux",
"npmFileMap": [
Expand Down
35 changes: 17 additions & 18 deletions webpack.config.js → rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
'use strict';

var webpack = require('webpack')
import nodeResolve from 'rollup-plugin-node-resolve';
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 = {
module: {
loaders: [
{ test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ }
]
},
output: {
library: 'Redux',
libraryTarget: 'umd'
},
format: 'umd',
moduleName: 'Redux',
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.DefinePlugin({
nodeResolve({
jsnext: true
}),
babel({
exclude: 'node_modules/**'
}),
replace({
'process.env.NODE_ENV': JSON.stringify(env)
})
]
};
}

if (env === 'production') {
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compressor: {
uglify({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
Expand All @@ -41,4 +40,4 @@ if (env === 'production') {
)
}

module.exports = config
export default config
8 changes: 3 additions & 5 deletions src/combineReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { ActionTypes } from './createStore'
import isPlainObject from 'lodash/isPlainObject'
import warning from './utils/warning'

const NODE_ENV = typeof process !== 'undefined' ? process.env.NODE_ENV : 'development'

function getUndefinedStateErrorMessage(key, action) {
const actionType = action && action.type
const actionName = (actionType && `"${actionType.toString()}"`) || 'an action'
Expand Down Expand Up @@ -107,7 +105,7 @@ export default function combineReducers(reducers) {
for (let i = 0; i < reducerKeys.length; i++) {
const key = reducerKeys[i]

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

let unexpectedKeyCache
if (NODE_ENV !== 'production') {
if (process.env.NODE_ENV !== 'production') {
unexpectedKeyCache = {}
}

Expand All @@ -136,7 +134,7 @@ export default function combineReducers(reducers) {
throw sanityError
}

if (NODE_ENV !== 'production') {
if (process.env.NODE_ENV !== 'production') {
const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache)
if (warningMessage) {
warning(warningMessage)
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import warning from './utils/warning'
function isCrushed() {}

if (
typeof process !== 'undefined' &&
process.env.NODE_ENV !== 'production' &&
typeof isCrushed.name === 'string' &&
isCrushed.name !== 'isCrushed'
Expand Down
Loading

0 comments on commit bf13473

Please sign in to comment.