Skip to content

Commit 89201a5

Browse files
committed
Completed Readme and added parameter build:example in package.json
1 parent 28b9100 commit 89201a5

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
1-
# react-async-loading
1+
# React Async Loading
2+
3+
```js
4+
import { AsyncComponent } from 'react-async-loading';
5+
// And export module...
6+
export default AsyncComponent(() => System.import('./Link.js'));
7+
```
8+
29
Code splitting to React and Webpack
10+
11+
## Install
12+
13+
- Install the module: `npm install --save react-async-loading`
14+
- Add plugin to you Webpack config:
15+
```js
16+
new webpack.optimize.CommonsChunkPlugin({
17+
children: true, // necessary for splitting children chunks
18+
async: true // necessary for async loading chunks
19+
})
20+
```
21+
22+
## Example
23+
- [Simple](https://github.com/Tom910/react-async-loading/example)
24+
25+
## API
26+
27+
### AsyncComponent
28+
#### Usage
29+
```jsx
30+
AsyncComponent(() => System.import('./Link.js'), { placeholder: <div>Loading</div> })
31+
```
32+
or
33+
```jsx
34+
AsyncComponent(() => require.ensure([], (require) => require('./Button.js'), 'Button'), { placeholder: <div>Loading</div> })
35+
```
36+
37+
#### Props
38+
##### - 1 argument
39+
Required. There should be a function of the module is loaded. Webpack supports two varieties of modules. `SystemJS` and `require.ensure`. The only difference is in the syntax, and that you can specify the name of the chunk in require.ensure
40+
- ``` System.import('./Link.js') ```
41+
- ``` require.ensure([], (require) => require('./Button.js'), 'Button') ```
42+
43+
Webpack compiles
44+
- `0.chunk.js` - numbers name in `SystemJS`
45+
- `Button.chunk.js` - we set the name in `require.ensure`
46+
47+
##### - 2 argument
48+
Setting options. Now available `placeholder` option, which displays the item is loaded chunk

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"build": "npm run build:lib && npm run build:dist",
1717
"build:lib": "babel src --out-dir lib",
1818
"build:dist": "webpack src/index.js dist/react-async-loading.min.js",
19+
"build:example": "webpack --config ./example/webpack.config.js",
1920
"clean": "rimraf lib dist",
2021
"prepublish": "npm run clean && npm run build"
2122
},

0 commit comments

Comments
 (0)