Node
The following Node.js options configure whether to polyfill or mock certain Node.js globals.
This feature is provided by webpack's internal NodeStuffPlugin plugin.
node
boolean: false object
webpack.config.js
module.exports = {
//...
node: {
global: false,
__filename: false,
__dirname: false,
},
};
Since webpack 3.0.0, the node option may be set to false to completely turn off the NodeStuffPlugin plugin.
node.global
boolean 'warn'
See the Node.js documentation for the exact behavior of this object.
Options:
-
true: Provide a polyfill. -
false: Provide nothing. Code that expects this object may crash with aReferenceError. -
'warn': Show a warning when usingglobal.
node.__filename
boolean 'mock' | 'warn-mock' | 'eval-only'
Options:
-
true: The filename of the input file relative to thecontextoption. -
false: Webpack won't touch your__filenamecode, which means you have the regular Node.js__filenamebehavior. The filename of the output file when run in a Node.js environment. -
'mock': The fixed value'/index.js'. -
'warn-mock': Use the fixed value of'/index.js'but show a warning. 'eval-only'
node.__dirname
boolean 'mock' | 'warn-mock' | 'eval-only'
Options:
-
true: The dirname of the input file relative to thecontextoption. -
false: Webpack won't touch your__dirnamecode, which means you have the regular Node.js__dirnamebehavior. The dirname of the output file when run in a Node.js environment. -
'mock': The fixed value'/'. -
'warn-mock': Use the fixed value of'/'but show a warning. 'eval-only'
© JS Foundation and other contributors
Licensed under the Creative Commons Attribution License 4.0.
https://webpack.js.org/configuration/node