You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/en/config/node.mdx
+46-10Lines changed: 46 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,23 +8,37 @@ The following Node.js options configure whether to polyfill or mock certain [Nod
8
8
9
9
## node.global
10
10
11
-
-**Type:**`boolean``'warn'`
11
+
-**Type:**`boolean | 'warn'`
12
12
-**Default:**`'warn'`
13
13
14
+
Controls whether Rspack should provide a polyfill for the Node.js `global` object when bundling for non-Node environments.
15
+
14
16
See [the Node.js documentation](https://nodejs.org/api/globals.html#globals_global) for the exact behavior of this object.
15
17
16
-
Options:
18
+
Optional values:
19
+
20
+
-`true`: Rspack injects a polyfill so that `global` is available in the bundle. This ensures compatibility with code that relies on Node.js globals in non-Node runtimes.
21
+
-`false`: No polyfill is provided. References to `global` remain untouched. If your target environment does not define `global`, accessing it will throw a `ReferenceError` at runtime.
22
+
-`'warn'`: Inject a polyfill like `true`, but also emit a warning when `global` is used.
23
+
24
+
For example, to disable `global` polyfill:
17
25
18
-
-`true`: Provide a polyfill.
19
-
-`false`: Provide nothing. Code that expects this object may crash with a `ReferenceError`.
-**Default:**`'warn-mock'`, `'node-module'` when [output.module](/config/output#outputmodule) is enabled
38
+
39
+
Controls how Rspack handles the Node.js [`__filename`](https://nodejs.org/api/modules.html#__filename) variable when bundling for non-Node environments.
26
40
27
-
Options:
41
+
Optional values:
28
42
29
43
-`true`: The filename of the input file relative to the [`context`](/config/context) option.
30
44
-`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.
@@ -33,16 +47,38 @@ Options:
33
47
-`'node-module'`: Replace `__filename` in CommonJS modules to `fileURLToPath(import.meta.url)` when `output.module` is enabled.
-**Default:**`'warn-mock'`, `'node-module'` when `output.module` is enabled
40
64
41
-
Options:
65
+
Controls how Rspack handles the Node.js [`__dirname`](https://nodejs.org/api/modules.html#__dirname) variable when bundling for non-Node environments.
66
+
67
+
Optional values:
42
68
43
69
-`true`: The dirname of the **input** file relative to the [`context`](/config/context) option.
44
70
-`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.
45
71
-`'mock'`: The fixed value `'/'`.
46
72
-`'warn-mock'`: Use the fixed value of `'/'` but show a warning.
47
73
-`'node-module'`: Replace `__dirname` in CommonJS modules to `fileURLToPath(import.meta.url + "/..")` when `output.module` is enabled.
0 commit comments