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'
Controls whether Rspack should provide a polyfill for the Node.js global object when bundling for non-Node environments.
See the Node.js documentation for the exact behavior of this object.
Optional values:
true: Rspack injects a polyfill so thatglobalis available in the bundle. This ensures compatibility with code that relies on Node.js globals in non-Node runtimes.false: No polyfill is provided. References toglobalremain untouched. If your target environment does not defineglobal, accessing it will throw aReferenceErrorat runtime.'warn': Inject a polyfill liketrue, but also emit a warning whenglobalis used.
For example, to disable global polyfill:
node.__filename
- Type:
boolean | 'mock' | 'warn-mock' | 'eval-only' - Default:
'warn-mock','node-module'when output.module is enabled
Controls how Rspack handles the Node.js __filename variable when bundling for non-Node environments.
Optional values:
true: The filename of the input file relative to thecontextoption.false: Rspack 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.'node-module': Replace__filenamein CommonJS modules tofileURLToPath(import.meta.url)whenoutput.moduleis enabled.'eval-only': Equivalent tofalse.
For example, to leave __filename as it is:
node.__dirname
- Type:
boolean | 'mock' | 'warn-mock' | 'eval-only' - Default:
'warn-mock','node-module'whenoutput.moduleis enabled
Controls how Rspack handles the Node.js __dirname variable when bundling for non-Node environments.
Optional values:
true: The dirname of the input file relative to thecontextoption.false: Rspack 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.'node-module': Replace__dirnamein CommonJS modules tofileURLToPath(import.meta.url + "/..")whenoutput.moduleis enabled.'eval-only': Equivalent tofalse.
For example, to leave __dirname as it is:

