Skip to content

Commit 9ae4ec5

Browse files
committed
Build UMD correctly
1 parent 621539d commit 9ae4ec5

File tree

4 files changed

+77
-33
lines changed

4 files changed

+77
-33
lines changed

.babelrc

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
{
2-
"presets": ["es2015", "stage-0"],
3-
"plugins": [
4-
"add-module-exports"
5-
]
2+
"plugins": [
3+
["transform-es2015-template-literals", { "loose": true }],
4+
"transform-es2015-literals",
5+
"transform-es2015-function-name",
6+
"transform-es2015-arrow-functions",
7+
"transform-es2015-block-scoped-functions",
8+
["transform-es2015-classes", { "loose": true }],
9+
"transform-es2015-object-super",
10+
"transform-es2015-shorthand-properties",
11+
["transform-es2015-computed-properties", { "loose": true }],
12+
["transform-es2015-for-of", { "loose": true }],
13+
"transform-es2015-sticky-regex",
14+
"transform-es2015-unicode-regex",
15+
"check-es2015-constants",
16+
["transform-es2015-spread", { "loose": true }],
17+
"transform-es2015-parameters",
18+
["transform-es2015-destructuring", { "loose": true }],
19+
"transform-es2015-block-scoping",
20+
"transform-es3-member-expression-literals",
21+
"transform-es3-property-literals",
22+
],
23+
"env": {
24+
"commonjs": {
25+
"plugins": [
26+
["transform-es2015-modules-commonjs", { "loose": true }],
27+
]
28+
},
29+
}
630
}

package.json

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
"jsnext:main": "es/index.js",
77
"files": [
88
"lib",
9+
"es",
910
"src"
1011
],
1112
"scripts": {
12-
"build": "babel src --out-dir lib",
13-
"prepublish": "npm run test && rimraf lib && npm run build",
14-
"test": "mocha --compilers js:babel-core/register --reporter spec test/*.js",
13+
"clean": "rimraf lib dist es",
14+
"build": "npm run build:commonjs && npm run build:umd && npm run build:umd:min && npm run build:es",
15+
"prepublish": "npm run clean && npm run test && npm run build",
1516
"posttest": "npm run lint",
1617
"lint": "eslint src test",
17-
"build": "npm run build:commonjs && npm run build:umd && npm run build:umd:min && npm run build:es",
18-
"build:commonjs": "babel src --out-dir lib",
19-
"build:es": "BABEL_ENV=es babel src --out-dir es",
20-
"build:umd": "NODE_ENV=development webpack",
21-
"build:umd:min": "NODE_ENV=production webpack"
18+
"test": "cross-env BABEL_ENV=commonjs mocha --compilers js:babel-core/register --reporter spec test/*.js",
19+
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
20+
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",
21+
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack",
22+
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack"
2223
},
2324
"repository": {
2425
"type": "git",
@@ -35,20 +36,37 @@
3536
"author": "Dan Abramov <dan.abramov@me.com>",
3637
"license": "MIT",
3738
"devDependencies": {
38-
"babel": "^6.1.18",
39-
"babel-cli": "^6.2.0",
40-
"babel-core": "^6.2.1",
39+
"babel-cli": "^6.6.5",
40+
"babel-core": "^6.6.5",
4141
"babel-eslint": "^5.0.0-beta4",
4242
"babel-loader": "^6.2.4",
43-
"babel-plugin-add-module-exports": "^0.1.1",
44-
"babel-preset-es2015": "^6.1.18",
45-
"babel-preset-stage-0": "^6.1.18",
43+
"babel-plugin-check-es2015-constants": "^6.6.5",
44+
"babel-plugin-transform-es2015-arrow-functions": "^6.5.2",
45+
"babel-plugin-transform-es2015-block-scoped-functions": "^6.6.5",
46+
"babel-plugin-transform-es2015-block-scoping": "^6.6.5",
47+
"babel-plugin-transform-es2015-classes": "^6.6.5",
48+
"babel-plugin-transform-es2015-computed-properties": "^6.6.5",
49+
"babel-plugin-transform-es2015-destructuring": "^6.6.5",
50+
"babel-plugin-transform-es2015-for-of": "^6.6.0",
51+
"babel-plugin-transform-es2015-function-name": "^6.5.0",
52+
"babel-plugin-transform-es2015-literals": "^6.5.0",
53+
"babel-plugin-transform-es2015-modules-commonjs": "^6.6.5",
54+
"babel-plugin-transform-es2015-object-super": "^6.6.5",
55+
"babel-plugin-transform-es2015-parameters": "^6.6.5",
56+
"babel-plugin-transform-es2015-shorthand-properties": "^6.5.0",
57+
"babel-plugin-transform-es2015-spread": "^6.6.5",
58+
"babel-plugin-transform-es2015-sticky-regex": "^6.5.0",
59+
"babel-plugin-transform-es2015-template-literals": "^6.6.5",
60+
"babel-plugin-transform-es2015-unicode-regex": "^6.5.0",
61+
"babel-plugin-transform-es3-member-expression-literals": "^6.5.0",
62+
"babel-plugin-transform-es3-property-literals": "^6.5.0",
4663
"chai": "^3.2.0",
64+
"cross-env": "^1.0.7",
4765
"eslint": "^1.10.2",
4866
"eslint-config-airbnb": "1.0.2",
4967
"eslint-plugin-react": "^4.1.0",
5068
"mocha": "^2.2.5",
51-
"rimraf": "^2.4.3",
69+
"rimraf": "^2.5.2",
5270
"webpack": "^1.12.14"
5371
}
5472
}

src/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
function thunkMiddleware({ dispatch, getState }) {
2-
return next => action =>
3-
typeof action === 'function' ?
4-
action(dispatch, getState) :
5-
next(action);
6-
}
1+
export default function thunkMiddleware({ dispatch, getState }) {
2+
return next => action => {
3+
if (typeof action === 'function') {
4+
return action(dispatch, getState);
5+
}
76

8-
module.exports = thunkMiddleware;
7+
return next(action);
8+
};
9+
}

webpack.config.babel.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import webpack from 'webpack';
22
import path from 'path';
33

4-
const { NODE_ENV, TARGET } = process.env;
4+
const { NODE_ENV } = process.env;
55

6-
const plugins = [
6+
const plugins = [
77
new webpack.optimize.OccurenceOrderPlugin(),
88
new webpack.DefinePlugin({
9-
'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
9+
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
1010
}),
1111
];
1212

@@ -19,16 +19,16 @@ NODE_ENV === 'production' && plugins.push(
1919
unsafe: true,
2020
unsafe_comps: true,
2121
screw_ie8: true,
22-
warnings: false
23-
}
22+
warnings: false,
23+
},
2424
})
2525
);
2626

2727
export default {
2828
module: {
2929
loaders: [
30-
{ test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ }
31-
]
30+
{ test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ },
31+
],
3232
},
3333

3434
entry: [
@@ -38,6 +38,7 @@ export default {
3838
output: {
3939
path: path.join(__dirname, 'dist'),
4040
filename,
41+
library: 'ReduxThunk',
4142
libraryTarget: 'umd',
4243
},
4344

0 commit comments

Comments
 (0)