UNPKG

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