UNPKG

1.66 kBMarkdownView Raw
1# react-proxy-loader
2
3Wraps a react component in a proxy component to enable Code Splitting (loads a react component and its dependencies on demand).
4
5## installation
6
7`npm install react-proxy-loader`
8
9## Usage
10
11[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
12
13``` js
14var Component = require("react-proxy!./Component");
15// => returns the proxied component (It loads on demand.)
16// (webpack creates an additional chunk for this component and its dependencies)
17
18var ComponentProxyMixin = require("react-proxy!./Component").Mixin;
19// => returns a mixin for the proxied component
20// (This allows you to setup rendering for the loading state for the proxy)
21var ComponentProxy = React.createClass({
22 mixins: [ComponentProxyMixin],
23 renderUnavailable: function() {
24 return <p>Loading...</p>;
25 }
26});
27```
28
29The proxy is a react component. All properties are transferred to the wrapped component.
30
31### Configuration
32
33Instead of (or in addition to) inlining the loader call you can also specify the proxied components in your configuration:
34
35``` js
36module.exports = {
37 module: {
38 loaders: [
39 /* ... */
40 {
41 test: [
42 /component\.jsx$/, // select component by RegExp
43 /\.async\.jsx$/, // select component by extension
44 "/abs/path/to/component.jsx" // absolute path to component
45 ],
46 loader: "react-proxy"
47 }
48 ]
49 }
50};
51```
52
53### Chunk name
54
55You can give the chunk a name with the `name` query parameter:
56
57``` js
58var Component = require("react-proxy?name=chunkName!./Component");
59```
60
61# License
62
63MIT (http://www.opensource.org/licenses/mit-license.php)