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: src/content/configuration/module.mdx
+93-17Lines changed: 93 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -277,11 +277,15 @@ module.exports = {
277
277
// Enable/disable `@import` at-rules handling, available since webpack 5.97.0
278
278
// type: boolean
279
279
import:true,
280
+
// Enable/disable url()/image-set()/src()/image() functions handling, available since webpack 5.97.0
281
+
// type: boolean
282
+
url:true,
280
283
// Use ES modules named export for css exports, available since webpack 5.90.0
281
284
// type: boolean
282
285
namedExports:true,
283
-
// Enable/disable url()/image-set()/src()/image() functions handling, available since webpack 5.97.0
284
-
url:true,
286
+
// Configure how CSS content is exported
287
+
// type: string
288
+
exportType:'link',
285
289
},
286
290
'css/auto': {
287
291
// ditto
@@ -354,6 +358,39 @@ This option enables the handling of `@import` at-rules in CSS files. When set to
354
358
355
359
T> To filter specific imports, you can use Webpack's built-in [IgnorePlugin](/plugins/ignore-plugin/). The [`filter` option](/loaders/css-loader/#filter), as available in `css-loader`, is not supported.
356
360
361
+
#### module.parser.css.url
362
+
363
+
This option enables or disables the handling of URLs in functions such as `url()`, `image-set()`, `src()`, and `image()` within CSS files. When enabled, these URLs are resolved and processed by webpack.
364
+
365
+
- Type: `boolean`
366
+
- Available: 5.97.0+
367
+
- Example:
368
+
369
+
```js
370
+
module.exports= {
371
+
module: {
372
+
parser: {
373
+
css: {
374
+
url:true,
375
+
},
376
+
},
377
+
},
378
+
};
379
+
```
380
+
381
+
```css
382
+
/* styles.css */
383
+
.background {
384
+
background-image: url('./images/bg.jpg');
385
+
}
386
+
387
+
.icon {
388
+
content: image('./icons/star.svg');
389
+
}
390
+
```
391
+
392
+
T> To filter specific imports, you can use Webpack's built-in [IgnorePlugin](/plugins/ignore-plugin/). The [`filter` option](/loaders/css-loader/#filter), as available in `css-loader`, is not supported.
393
+
357
394
#### module.parser.css.namedExports
358
395
359
396
This option enables the use of ES modules named export for CSS exports. When set to `true`, the CSS module will export its classes and styles using named exports.
By enabling `namedExports`, you adopt a more modular and maintainable approach to managing CSS in JavaScript projects, leveraging ES module syntax for clearer and more explicit imports.
409
446
410
-
####module.parser.css.url
447
+
### module.parser.css.exportType
411
448
412
-
This option enables or disables the handling of URLs in functions such as `url()`, `image-set()`, `src()`, and `image()` within CSS files. When enabled, these URLs are resolved and processed by webpack.
449
+
Configure how CSS content will be exported.
413
450
414
451
- Type: `boolean`
415
-
- Available: 5.97.0+
452
+
- Available: 5.102.0+
416
453
- Example:
417
454
418
455
```js
419
456
module.exports= {
420
457
module: {
421
458
parser: {
422
459
css: {
423
-
url:true,
460
+
// ...
461
+
exportType:'text',
424
462
},
425
463
},
426
464
},
427
465
};
428
466
```
429
467
430
-
```css
431
-
/* styles.css */
432
-
.background {
433
-
background-image: url('./images/bg.jpg');
434
-
}
435
-
436
-
.icon {
437
-
content: image('./icons/star.svg');
438
-
}
439
-
```
468
+
Possible values: `'link' | 'text' | 'css-style-sheet'
440
469
441
-
T> To filter specific imports, you can use Webpack's built-in [IgnorePlugin](/plugins/ignore-plugin/). The [`filter` option](/loaders/css-loader/#filter), as available in `css-loader`, is not supported.
470
+
-`link` - extract CSS into own file and use `link` tags to inject into DOM.
471
+
-`text` - store CSS in JS file and return using default export.
472
+
-`css-style-sheet` - the default export is a constructable stylesheet (i.e. CSSStyleSheet). Useful for custom elements and shadow DOM.
Copy file name to clipboardExpand all lines: src/content/configuration/node.mdx
+17-7Lines changed: 17 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ The following Node.js options configure whether to polyfill or mock certain [Nod
17
17
18
18
This feature is provided by webpack's internal [`NodeStuffPlugin`](https://github.com/webpack/webpack/blob/main/lib/NodeStuffPlugin.js) plugin.
19
19
20
-
W> As of webpack 5, You can configure only `global`, `__filename` or `__dirname` under `node` option. If you're looking for how to polyfill `fs` alike in Node.js under webpack 5, please check [resolve.fallback](/configuration/resolve/#resolvefallback) for help.
20
+
W> As of webpack 5, You can configure only `global`, `__filename`/`import.meta.filename` or `__dirname`/`import.meta.dirname` under `node` option. If you're looking for how to polyfill `fs` alike in Node.js under webpack 5, please check [resolve.fallback](/configuration/resolve/#resolvefallback) for help.
21
21
22
22
## node
23
23
@@ -48,7 +48,7 @@ See [the Node.js documentation](https://nodejs.org/api/globals.html#globals_glob
48
48
49
49
Options:
50
50
51
-
-`true`: Provide a polyfill.
51
+
-`true`: Provide a polyfill or using `globalThis` if supported by your environment, see the [`environment`](/configuration/output/#outputenvironment) option.
52
52
-`false`: Provide nothing. Code that expects this object may crash with a `ReferenceError`.
53
53
-`'warn'`: Show a warning when using `global`.
54
54
@@ -59,11 +59,16 @@ Options:
59
59
Options:
60
60
61
61
-`true`: The filename of the **input** file relative to the [`context` option](/configuration/entry-context/#context).
62
-
-`false`: Webpack 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.
62
+
-`false`: Webpack won't touch your `__filename`and `import.meta.filename`code, which means you have the regular Node.js `__filename` and `import.meta.filename` behavior. The filename of the **output** file when run in a Node.js environment.
63
63
-`'mock'`: The fixed value `'/index.js'`.
64
64
-`'warn-mock'`: Use the fixed value of `'/index.js'` but show a warning.
65
-
-`'node-module'`: Replace `__filename` in CommonJS modules to `fileURLToPath(import.meta.url)` when `output.module` is enabled.
66
-
-`'eval-only'`
65
+
-`'node-module'`: Replace `__filename` in CommonJS modules and `import.meta.filename` code in ES modules to `fileURLToPath(import.meta.url)` when `output.module` is enabled.
66
+
-`'eval-only'`: Defer the resolution of `__filename`/`import.meta.filename` to the Node.js runtime at execution time, but evaluate them in construction like `require`/`import` to properly resolve modules. Replace `__filename` with `import.meta.filename` and vice versa depending on the `output.module` option (if your environment does not support `import.meta.filename`, the fallback will be used using `import.meta.url` to get this value).
67
+
68
+
The default value can be affected by different [`target`](/configuration/target/):
69
+
70
+
- Defaults to `'eval-only'` if [`target`](/configuration/target/) is set to `'node'` or node-like environments (`async-node`, `electron`) or mixed targets (`web` and `node` together).
71
+
- Defaults to `'mock'` if [`target`](/configuration/target/) is set to `'web'` or web-like environments.
67
72
68
73
## node.\_\_dirname
69
74
@@ -72,8 +77,13 @@ Options:
72
77
Options:
73
78
74
79
-`true`: The dirname of the **input** file relative to the [`context` option](/configuration/entry-context/#context).
75
-
-`false`: Webpack 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.
80
+
-`false`: Webpack won't touch your `__dirname`and `import.meta.dirname`code, which means you have the regular Node.js `__dirname` and `import.meta.dirname` behavior. The dirname of the **output** file when run in a Node.js environment.
76
81
-`'mock'`: The fixed value `'/'`.
77
82
-`'warn-mock'`: Use the fixed value of `'/'` but show a warning.
78
83
-`'node-module'`: Replace `__dirname` in CommonJS modules to `fileURLToPath(import.meta.url + "/..")` when `output.module` is enabled.
79
-
-`'eval-only'`
84
+
-`'eval-only'`: Defer the resolution of `__dirname`/`import.meta.dirname` to the Node.js runtime at execution time, but evaluate them in construction like `require`/`import` to properly resolve modules. Replace `__dirname` with `import.meta.dirname` and vice versa depending on the `output.module` option (if your environment does not support `import.meta.filename`, the fallback will be used using `import.meta.url` to get this value).
85
+
86
+
The default value can be affected by different [`target`](/configuration/target/):
87
+
88
+
- Defaults to `'eval-only'` if [`target`](/configuration/target/) is set to `'node'` or node-like environments (`async-node`, `electron`) or mixed targets (`web` and `node` together).
89
+
- Defaults to `'mock'` if [`target`](/configuration/target/) is set to `'web'` or web-like environments.
-`moduleFilenameTemplate` (`string`): See [`output.devtoolModuleFilenameTemplate`](/configuration/output/#outputdevtoolmodulefilenametemplate).
40
+
-`ignoreList` (`string|RegExp|array`): Decide whether to ignore source files that match the specified value in source maps.
41
41
-`module` (`boolean`): Indicates whether loaders should generate source maps (defaults to `true`).
42
+
-`moduleFilenameTemplate` (`string`): See [`output.devtoolModuleFilenameTemplate`](/configuration/output/#outputdevtoolmodulefilenametemplate).
42
43
-`columns` (`boolean`): Indicates whether column mappings should be used (defaults to `true`).
43
44
-`protocol` (`string`): Allows user to override default protocol (`webpack-internal://`)
45
+
-`namespace` (`string`): Namespace prefix to allow multiple webpack roots in the devtools. See [`output.devtoolNamespace`](/configuration/output/#outputdevtoolnamespace).
46
+
-`noSources = false` (`boolean`): Prevents the source file content from being included in the source map.
47
+
-`sourceRoot` (`string`): Provide a custom value for the `sourceRoot` property in source maps.
48
+
-`debugIds` (`boolean`): If `true`, unique ids will be emitted in source and sourcemaps which streamlines identifying sourcemaps across different builds. See the [TC39 sourcemap debug ID proposal](https://github.com/tc39/ecma426/blob/main/proposals/debug-id.md) for more details.
44
49
45
50
T> Setting `module` and/or `columns` to `false` will yield less accurate source maps but will also improve compilation performance significantly.
-`columns = true` (`boolean`): Indicates whether column mappings should be used.
44
+
-`namespace` (`string`): Namespace prefix to allow multiple webpack roots in the devtools. See [`output.devtoolNamespace`](/configuration/output/#outputdevtoolnamespace).
44
45
-`noSources = false` (`boolean`): Prevents the source file content from being included in the source map.
45
46
-`publicPath` (`string`): Emits absolute URLs with public path prefix, e.g. `https://example.com/project/`.
46
47
-`fileContext` (`string`): Makes the `[file]` argument relative to this directory.
0 commit comments