diff --git a/content/configuration/node.md b/content/configuration/node.md index 059a94055fd3..7a5635341a98 100644 --- a/content/configuration/node.md +++ b/content/configuration/node.md @@ -5,9 +5,12 @@ contributors: - sokra - skipjack - oneforwonder + - Rob--W --- -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). +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) 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. ## `node` @@ -19,7 +22,7 @@ This is an object where each property is the name of a Node global or module and - `true`: Provide a polyfill. - `"mock"`: Provide a mock that implements the expected interface but has little or no functionality. - `"empty"`: Provide an empty object. -- `false`: Provide nothing. Code that expects this object to be defined may crash. +- `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. 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. @@ -34,10 +37,12 @@ node: { __dirname: "mock", Buffer: true, setImmediate: true + + // See "Other node core libraries" for additional options. } ``` -Since webpack 3.0.0, the `node` option may be set to `false` to turn off the `NodeSourcePlugin` completely. +Since webpack 3.0.0, the `node` option may be set to `false` to completely turn off the `NodeStuffPlugin` and `NodeSourcePlugin` plugins. ## `node.console` @@ -109,9 +114,13 @@ Default: `true` `boolean | "mock" | "empty"` -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). +W> This option is only activated (via `NodeSourcePlugin`) when the target is unspecified, "web" or "webworker". + +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). + +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. -By default, Webpack will polyfill each library if there is a known polyfill or do nothing if there is not one. +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')`. Example: