Skip to content

Commit 6675385

Browse files
authored
add UMD build (#117)
1 parent 812d5f2 commit 6675385

File tree

5 files changed

+88
-11
lines changed

5 files changed

+88
-11
lines changed

.gitignore

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

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ node_js:
33
- "6"
44
- "5"
55
- "4"
6+
script:
7+
- npm run lint
8+
- npm test
9+
- npm run build

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
redux-actions
2-
=============
1+
# redux-actions
32

43
[![build status](https://img.shields.io/travis/acdlite/redux-actions/master.svg?style=flat-square)](https://travis-ci.org/acdlite/redux-actions)
54
[![npm version](https://img.shields.io/npm/v/redux-actions.svg?style=flat-square)](https://www.npmjs.com/package/redux-actions)
65

76
[Flux Standard Action](https://github.com/acdlite/flux-standard-action) utilities for Redux.
87

9-
```js
8+
## Installation
9+
10+
```bash
1011
npm install --save redux-actions
1112
```
12-
```js
13-
import { createAction, handleAction, handleActions } from 'redux-actions';
14-
```
13+
14+
If you don’t use [npm](https://www.npmjs.com), you may grab the latest [UMD](https://npmcdn.com/redux-actions@latest/dist) build from [npmcdn](https://npmcdn.com) (either a [development](https://npmcdn.com/redux-actions@latest/dist/redux-actions.js) or a [production](https://npmcdn.com/redux-actions@latest/dist/redux-actions.min.js) build). The UMD build exports a global called `window.ReduxActions` if you add it to your page via a `<script>` tag. We *don’t* recommend UMD builds for any serious application, as most of the libraries complementary to Redux are only available on [npm](https://www.npmjs.com/search?q=redux).
15+
16+
## Usage
1517

1618
### `createAction(type, payloadCreator = Identity, ?metaCreator)`
1719

20+
```js
21+
import { createAction } from 'redux-actions';
22+
```
23+
1824
Wraps an action creator so that its return value is the payload of a Flux Standard Action. If no payload creator is passed, or if it's not a function, the identity function is used.
1925

2026
Example:
@@ -80,6 +86,10 @@ createAction('ADD_TODO')('Use Redux');
8086

8187
### `createActions(?actionsMap, ?...identityActions)`
8288

89+
```js
90+
import { createActions } from 'redux-actions';
91+
```
92+
8393
Returns an object mapping action types to action creators. The keys of this object are camel-cased from the keys in `actionsMap` and the string literals of `identityActions`; the values are the action creators.
8494

8595
`actionsMap` is an optional object with action types as keys, and whose values **must** be either
@@ -94,7 +104,7 @@ Returns an object mapping action types to action creators. The keys of this obje
94104
const { actionOne, actionTwo, actionThree } = createActions({
95105
// function form; payload creator defined inline
96106
ACTION_ONE: (key, value) => ({ [key]: value }),
97-
107+
98108
// array form
99109
ACTION_TWO: [
100110
(first) => first, // payload
@@ -123,6 +133,10 @@ expect(actionThree(3)).to.deep.equal({
123133

124134
### `handleAction(type, reducer | reducerMap, ?defaultState)`
125135

136+
```js
137+
import { handleAction } from 'redux-actions';
138+
```
139+
126140
Wraps a reducer so that it only handles Flux Standard Actions of a certain type.
127141

128142
If a single reducer is passed, it is used to handle both normal actions and failed actions. (A failed action is analogous to a rejected promise.) You can use this form if you know a certain type of action will never fail, like the increment example above.
@@ -142,6 +156,10 @@ The optional third parameter specifies a default or initial state, which is used
142156

143157
### `handleActions(reducerMap, ?defaultState)`
144158

159+
```js
160+
import { handleActions } from 'redux-actions';
161+
```
162+
145163
Creates multiple reducers using `handleAction()` and combines them into a single reducer that handles multiple actions. Accepts a map where the keys are passed as the first parameter to `handleAction()` (the action type), and the values are passed as the second parameter (either a reducer or reducer map).
146164

147165
The optional second parameter specifies a default or initial state, which is used when `undefined` is passed to the reducer.

package.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44
"description": "Flux Standard Action utlities for Redux",
55
"main": "lib/index.js",
66
"scripts": {
7-
"build": "npm run clean && babel src --out-dir lib --ignore *-test.js",
7+
"build:commonjs": "babel src --out-dir lib --ignore *-test.js",
8+
"build:umd": "cross-env NODE_ENV=development webpack",
9+
"build:umd:min": "cross-env NODE_ENV=production webpack",
10+
"build": "npm run clean && npm run build:commonjs && npm run build:umd && npm run build:umd:min",
811
"clean": "rimraf lib",
9-
"lint": "esw src --color",
12+
"lint": "esw src webpack.config --color",
13+
"lint:fix": "npm run lint -- --fix",
1014
"lint:watch": "npm run lint -- --watch",
1115
"prepublish": "npm run lint && npm run test && npm run build",
1216
"test": "mocha --compilers js:babel-register src/**/*-test.js",
1317
"test:watch": "npm run test -- --watch src/**/*-test.js"
1418
},
1519
"files": [
16-
"lib"
20+
"lib",
21+
"dist"
1722
],
1823
"keywords": [
1924
"flux",
@@ -35,17 +40,20 @@
3540
"babel-cli": "^6.7.7",
3641
"babel-core": "^6.7.7",
3742
"babel-eslint": "^6.1.1",
43+
"babel-loader": "^6.2.4",
3844
"babel-preset-es2015": "^6.6.0",
3945
"babel-preset-stage-0": "^6.5.0",
4046
"babel-register": "^6.7.2",
4147
"chai": "^3.0.0",
48+
"cross-env": "^2.0.0",
4249
"eslint": "^2.8.0",
4350
"eslint-config-airbnb-base": "^1.0.3",
4451
"eslint-plugin-import": "^1.5.0",
4552
"eslint-watch": "^2.1.13",
4653
"flux-standard-action": "^0.6.0",
4754
"mocha": "^2.2.5",
48-
"rimraf": "^2.5.3"
55+
"rimraf": "^2.5.3",
56+
"webpack": "^1.13.1"
4957
},
5058
"dependencies": {
5159
"lodash": "^4.13.1",

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+
const production = NODE_ENV === 'production';
6+
7+
const plugins = [
8+
new webpack.optimize.OccurenceOrderPlugin(),
9+
new webpack.DefinePlugin({
10+
'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
11+
})
12+
];
13+
14+
if (production) {
15+
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+
28+
export default {
29+
entry: path.join(__dirname, 'src/index.js'),
30+
output: {
31+
path: path.join(__dirname, 'dist'),
32+
filename: `redux-actions${production ? '.min' : ''}.js`,
33+
library: 'ReduxActions',
34+
libraryTarget: 'umd'
35+
},
36+
module: {
37+
loaders: [
38+
{
39+
test: /\.js$/,
40+
loaders: ['babel-loader'],
41+
exclude: /node_modules/
42+
}
43+
]
44+
},
45+
plugins
46+
};

0 commit comments

Comments
 (0)