1 | # expose loader for webpack
|
2 |
|
3 | The expose loader adds modules to the global object. This is useful
|
4 | for debugging, or supporting libraries that depend on libraries in
|
5 | globals.
|
6 |
|
7 | **Note**: Modules must be `require()`'d within in your bundle, or they will not
|
8 | be exposed.
|
9 |
|
10 | ## Usage
|
11 |
|
12 | ``` javascript
|
13 | require("expose-loader?libraryName!./file.js");
|
14 | // Exposes the exports for file.js to the global context on property "libraryName".
|
15 | // In web browsers, window.libraryName is then available.
|
16 | ```
|
17 |
|
18 | This line works to expose React to the web browser to enable the Chrome React devtools:
|
19 |
|
20 | ```
|
21 | require("expose-loader?React!react");
|
22 | ```
|
23 |
|
24 | Thus, `window.React` is then available to the Chrome React devtools extension.
|
25 |
|
26 | Alternately, you can set this in your config file:
|
27 |
|
28 | ```
|
29 | module: {
|
30 | loaders: [
|
31 | { test: require.resolve("react"), loader: "expose-loader?React" }
|
32 | ]
|
33 | }
|
34 | ```
|
35 | Also for multiple expose you can use `!` in loader string:
|
36 | ```
|
37 | module: {
|
38 | loaders: [
|
39 | { test: require.resolve("jquery"), loader: "expose-loader?$!expose-loader?jQuery" },
|
40 | ]
|
41 | }
|
42 | ```
|
43 |
|
44 | The `require.resolve` is a node.js call (unrelated to `require.resolve` in webpack
|
45 | processing -- check the node.js docs instead). `require.resolve` gives you the
|
46 | absolute path to the module ("/.../app/node_modules/react/react.js"). So the
|
47 | expose only applies to the react module. And it's only exposed when used in the
|
48 | bundle.
|
49 |
|
50 |
|
51 | [Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
|
52 |
|
53 | ## License
|
54 |
|
55 | MIT (http://www.opensource.org/licenses/mit-license.php)
|