CC 4.0 License

The content of this section is derived from the content of the following links and is subject to the CC BY 4.0 license.

The following contents can be assumed to be the result of modifications and deletions based on the original contents if not specifically stated.

Node

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

node.global

  • Type: boolean 'warn'
  • Default: '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 a ReferenceError.
  • 'warn': Show a warning when using global.

node.__filename

  • Type: boolean 'mock' | 'warn-mock' | 'eval-only'
  • Default: 'warn-mock', 'node-module' when output.module is enabled

Options:

  • true: The filename of the input file relative to the context option.
  • false: Rspack won't touch your __filename code, which means you have the regular Node.js __filename behavior. 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.
  • 'node-module': Replace __filename in CommonJS modules to fileURLToPath(import.meta.url) when output.module is enabled.
  • 'eval-only': Equivalent to false.

node.__dirname

  • Type: boolean 'mock' | 'warn-mock' | 'eval-only'
  • Default: 'warn-mock', 'node-module' when output.module is enabled

Options:

  • true: The dirname of the input file relative to the context option.
  • false: Rspack won't touch your __dirname code, which means you have the regular Node.js __dirname behavior. 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.
  • 'node-module': Replace __dirname in CommonJS modules to fileURLToPath(import.meta.url + "/..") when output.module is enabled.
  • 'eval-only': Equivalent to false.