UNPKG

1.12 kBMarkdownView Raw
1# expose loader for webpack
2
3## Usage
4
5``` javascript
6require("expose?libraryName!./file.js");
7// Exposes the exports for file.js to the global context on property "libraryName".
8// In web browsers, window.libraryName is then available.
9```
10
11This line works to expose React to the web browser to enable the Chrome React devtools:
12
13```
14require("expose?React!react");
15```
16
17Thus, `window.React` is then available to the Chrome React devtools extension.
18
19Alternately, you can set this in your config file:
20
21```
22module: {
23 loaders: [
24 { test: require.resolve("react"), loader: "expose?React" }
25 ]
26}
27```
28
29The `require.resolve` is a node.js call (unrelated to `require.resolve` in webpack
30processing -- check the node.js docs instead). `require.resolve` gives you the
31absolute path to the module ("/.../app/node_modules/react/react.js"). So the
32expose only applies to the react module. And it's only exposed when used in the
33bundle.
34
35
36[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
37
38## License
39
40MIT (http://www.opensource.org/licenses/mit-license.php)