Skip to content

Commit 470b2d4

Browse files
committed
Merge pull request #59 from gaearon/umd
Add UMD build
2 parents 9e99c17 + 8f0f79f commit 470b2d4

File tree

6 files changed

+128
-28
lines changed

6 files changed

+128
-28
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
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ node_modules
22
coverage
33
*.log
44
lib
5+
dist
6+
es

.travis.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
language: node_js
2-
sudo: false
3-
cache:
4-
directories:
5-
- node_modules
62
node_js:
73
- "4"
84
- "5"
9-
before_install:
10-
- npm install -g babel-cli
5+
script:
6+
- npm run clean
7+
- npm run build
8+
- npm run test
9+
branches:
10+
only:
11+
- master

package.json

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@
33
"version": "1.0.3",
44
"description": "Thunk middleware for Redux.",
55
"main": "lib/index.js",
6+
"jsnext:main": "es/index.js",
67
"files": [
78
"lib",
9+
"es",
810
"src"
911
],
1012
"scripts": {
11-
"build": "babel src --out-dir lib",
12-
"prepublish": "npm run test && rimraf lib && npm run build",
13-
"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",
1416
"posttest": "npm run lint",
15-
"lint": "eslint src test"
17+
"lint": "eslint src test",
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"
1623
},
1724
"repository": {
1825
"type": "git",
@@ -29,18 +36,37 @@
2936
"author": "Dan Abramov <dan.abramov@me.com>",
3037
"license": "MIT",
3138
"devDependencies": {
32-
"babel": "^6.1.18",
33-
"babel-cli": "^6.2.0",
34-
"babel-core": "^6.2.1",
39+
"babel-cli": "^6.6.5",
40+
"babel-core": "^6.6.5",
3541
"babel-eslint": "^5.0.0-beta4",
36-
"babel-plugin-add-module-exports": "^0.1.1",
37-
"babel-preset-es2015": "^6.1.18",
38-
"babel-preset-stage-0": "^6.1.18",
42+
"babel-loader": "^6.2.4",
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",
3963
"chai": "^3.2.0",
64+
"cross-env": "^1.0.7",
4065
"eslint": "^1.10.2",
4166
"eslint-config-airbnb": "1.0.2",
4267
"eslint-plugin-react": "^4.1.0",
4368
"mocha": "^2.2.5",
44-
"rimraf": "^2.4.3"
69+
"rimraf": "^2.5.2",
70+
"webpack": "^1.12.14"
4571
}
4672
}

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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import webpack from 'webpack';
2+
import path from 'path';
3+
4+
const { NODE_ENV } = process.env;
5+
6+
const plugins = [
7+
new webpack.optimize.OccurenceOrderPlugin(),
8+
new webpack.DefinePlugin({
9+
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
10+
}),
11+
];
12+
13+
const filename = `redux-thunk${NODE_ENV === 'production' ? '.min' : ''}.js`;
14+
15+
NODE_ENV === 'production' && plugins.push(
16+
new webpack.optimize.UglifyJsPlugin({
17+
compressor: {
18+
pure_getters: true,
19+
unsafe: true,
20+
unsafe_comps: true,
21+
screw_ie8: true,
22+
warnings: false,
23+
},
24+
})
25+
);
26+
27+
export default {
28+
module: {
29+
loaders: [
30+
{ test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ },
31+
],
32+
},
33+
34+
entry: [
35+
'./src/index',
36+
],
37+
38+
output: {
39+
path: path.join(__dirname, 'dist'),
40+
filename,
41+
library: 'ReduxThunk',
42+
libraryTarget: 'umd',
43+
},
44+
45+
plugins,
46+
};

0 commit comments

Comments
 (0)