Movatterモバイル変換


[0]ホーム

URL:


webpack logo
ag grid
ag charts

Node

The following Node.js options configure whether to polyfill or mock certainNode.js globals.

This feature is provided by webpack's internalNodeStuffPlugin plugin.

warning

As of webpack 5, You can configure onlyglobal,__filename/import.meta.filename or__dirname/import.meta.dirname undernode option. If you're looking for how to polyfillfs alike in Node.js under webpack 5, please checkresolve.fallback for help.

node

falseobject

webpack.config.js

module.exports={// ...  node:{    global:false,    __filename:false,    __dirname:false,},};

Thenode option may be set tofalse to completely turn off theNodeStuffPlugin plugin.

node.global

boolean'warn'

tip

If you are using a module which needs global variables in it, useProvidePlugin instead ofglobal.

Seethe Node.js documentation for the exact behavior of this object.

Options:

  • true: Provide a polyfill or usingglobalThis if supported by your environment, see theenvironment option.
  • false: Provide nothing. Code that expects this object may crash with aReferenceError.
  • 'warn': Show a warning when usingglobal.

node.__filename

boolean'mock' | 'warn-mock' | 'node-module' | 'eval-only'

Options:

  • true: The filename of theinput file relative to thecontext option.
  • false: Webpack won't touch your__filename andimport.meta.filename code, which means you have the regular Node.js__filename andimport.meta.filename behavior. The filename of theoutput 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.
  • 'node-module': Replace__filename in CommonJS modules andimport.meta.filename code in ES modules tofileURLToPath(import.meta.url) whenoutput.module is enabled.
  • 'eval-only': Defer the resolution of__filename/import.meta.filename to the Node.js runtime at execution time, but evaluate them in construction likerequire/import to properly resolve modules. Replace__filename withimport.meta.filename and vice versa depending on theoutput.module option (if your environment does not supportimport.meta.filename, the fallback will be used usingimport.meta.url to get this value).

The default value can be affected by differenttarget:

  • Defaults to'eval-only' iftarget is set to'node' or node-like environments (async-node,electron) or mixed targets (web andnode together).
  • Defaults to'mock' iftarget is set to'web' or web-like environments.

node.__dirname

boolean'mock' | 'warn-mock' | 'node-module' | 'eval-only'

Options:

  • true: The dirname of theinput file relative to thecontext option.
  • false: Webpack won't touch your__dirname andimport.meta.dirname code, which means you have the regular Node.js__dirname andimport.meta.dirname behavior. The dirname of theoutput file when run in a Node.js environment.
  • 'mock': The fixed value'/'.
  • 'warn-mock': Use the fixed value of'/' but show a warning.
  • 'node-module': Replace__dirname in CommonJS modules tofileURLToPath(import.meta.url + "/..") whenoutput.module is enabled.
  • 'eval-only': Defer the resolution of__dirname/import.meta.dirname to the Node.js runtime at execution time, but evaluate them in construction likerequire/import to properly resolve modules. Replace__dirname withimport.meta.dirname and vice versa depending on theoutput.module option (if your environment does not supportimport.meta.filename, the fallback will be used usingimport.meta.url to get this value).

The default value can be affected by differenttarget:

  • Defaults to'eval-only' iftarget is set to'node' or node-like environments (async-node,electron) or mixed targets (web andnode together).
  • Defaults to'mock' iftarget is set to'web' or web-like environments.
« Previous
Dotenv
Next »
Stats

9 Contributors

sokraskipjackoneforwonderRob--WbyzykEugeneHlushkoanikethsahachenxsansnitin315

[8]ページ先頭

©2009-2026 Movatter.jp