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