You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/configuration/node.md
+14-5Lines changed: 14 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,12 @@ contributors:
5
5
- sokra
6
6
- skipjack
7
7
- oneforwonder
8
+
- Rob--W
8
9
---
9
10
10
-
These options configure whether to polyfill or mock certain [Node.js globals](https://nodejs.org/docs/latest/api/globals.html) and modules. This allows code originally written for the Node.js environment to run in other environments like the browser. This feature is provided by webpack's internal [`NodeStuffPlugin`](https://github.com/webpack/webpack/blob/master/lib/NodeStuffPlugin.js).
11
+
These options configure whether to polyfill or mock certain [Node.js globals](https://nodejs.org/docs/latest/api/globals.html) and modules. This allows code originally written for the Node.js environment to run in other environments like the browser.
12
+
13
+
This feature is provided by webpack's internal [`NodeStuffPlugin`](https://github.com/webpack/webpack/blob/master/lib/NodeStuffPlugin.js) plugin. If the target is "web" (default) or "webworker", the [`NodeSourcePlugin`](https://github.com/webpack/webpack/blob/master/lib/node/NodeSourcePlugin.js) plugin is also activated.
11
14
12
15
13
16
## `node`
@@ -19,7 +22,7 @@ This is an object where each property is the name of a Node global or module and
19
22
-`true`: Provide a polyfill.
20
23
-`"mock"`: Provide a mock that implements the expected interface but has little or no functionality.
21
24
-`"empty"`: Provide an empty object.
22
-
-`false`: Provide nothing. Code that expects this object to be defined may crash.
25
+
-`false`: Provide nothing. Code that expects this object may crash with a `ReferenceError`. Code that attempts to import the module using `require('modulename')`may trigger a `Cannot find module "modulename"` error.
23
26
24
27
W> Not every Node global supports all four options. The compiler will throw an error for property-value combinations that aren't supported (e.g. `process: 'empty'`). See the sections below for more details.
25
28
@@ -34,10 +37,12 @@ node: {
34
37
__dirname:"mock",
35
38
Buffer:true,
36
39
setImmediate:true
40
+
41
+
// See "Other node core libraries" for additional options.
37
42
}
38
43
```
39
44
40
-
Since webpack 3.0.0, the `node` option may be set to `false` to turn off the `NodeSourcePlugin`completely.
45
+
Since webpack 3.0.0, the `node` option may be set to `false` to completely turn off the `NodeStuffPlugin` and `NodeSourcePlugin`plugins.
41
46
42
47
43
48
## `node.console`
@@ -109,9 +114,13 @@ Default: `true`
109
114
110
115
`boolean | "mock" | "empty"`
111
116
112
-
Many other Node.js core libraries can be configured as well. See the list of [Node.js core libraries and their polyfills](https://github.com/webpack/node-libs-browser).
117
+
W> This option is only activated (via `NodeSourcePlugin`) when the target is unspecified, "web" or "webworker".
118
+
119
+
Polyfills for Node.js core libraries from [`node-libs-browser`](https://github.com/webpack/node-libs-browser) are used if available, when the `NodeSourcePlugin` plugin is enabled. See the list of [Node.js core libraries and their polyfills](https://github.com/webpack/node-libs-browser#readme).
120
+
121
+
By default, webpack will polyfill each library if there is a known polyfill or do nothing if there is not one. In the latter case, webpack will behave as if the module name was configured with the `false` value.
113
122
114
-
By default, Webpack will polyfill each library if there is a known polyfill or do nothing if there is not one.
123
+
T> To import a built-in module, use [`__non_webpack_require__`](/api/module-variables/#__non_webpack_require__-webpack-specific-), i.e. `__non_webpack_require__('modulename')` instead of `require('modulename')`.
0 commit comments