Skip to content

Commit 17aa07d

Browse files
docs: v5.103.0 (#7711)
1 parent 53bb91a commit 17aa07d

File tree

5 files changed

+122
-27
lines changed

5 files changed

+122
-27
lines changed

src/content/configuration/module.mdx

Lines changed: 93 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,15 @@ module.exports = {
277277
// Enable/disable `@import` at-rules handling, available since webpack 5.97.0
278278
// type: boolean
279279
import: true,
280+
// Enable/disable url()/image-set()/src()/image() functions handling, available since webpack 5.97.0
281+
// type: boolean
282+
url: true,
280283
// Use ES modules named export for css exports, available since webpack 5.90.0
281284
// type: boolean
282285
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',
285289
},
286290
'css/auto': {
287291
// ditto
@@ -354,6 +358,39 @@ This option enables the handling of `@import` at-rules in CSS files. When set to
354358

355359
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.
356360

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+
357394
#### module.parser.css.namedExports
358395

359396
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.
@@ -407,38 +444,32 @@ import { header, footer } from './styles.module.css';
407444

408445
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.
409446

410-
#### module.parser.css.url
447+
### module.parser.css.exportType
411448

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.
413450

414451
- Type: `boolean`
415-
- Available: 5.97.0+
452+
- Available: 5.102.0+
416453
- Example:
417454

418455
```js
419456
module.exports = {
420457
module: {
421458
parser: {
422459
css: {
423-
url: true,
460+
// ...
461+
exportType: 'text',
424462
},
425463
},
426464
},
427465
};
428466
```
429467

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'
440469

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.
442473

443474
### module.parser.javascript
444475

@@ -763,6 +794,51 @@ module.exports = {
763794
};
764795
```
765796

797+
### module.parser.json.namedExports
798+
799+
Allow named exports for json of object type.
800+
801+
- Type: `boolean`
802+
- Available: <Badge text='5.103.0+' />
803+
- Example:
804+
805+
```js
806+
module.exports = {
807+
module: {
808+
parser: {
809+
json: {
810+
// Example:
811+
// import { myField } from "./file.json";
812+
//
813+
// console.log(myField);
814+
namedExports: true,
815+
},
816+
},
817+
},
818+
};
819+
```
820+
821+
### module.parser.json.parse
822+
823+
Function to parser content and return JSON.
824+
825+
- Type: `((input: string) => Buffer | JsonValue)`
826+
- Example:
827+
828+
```js
829+
const json5 = require('json5');
830+
831+
module.exports = {
832+
module: {
833+
parser: {
834+
json: {
835+
parse: json5.parse,
836+
},
837+
},
838+
},
839+
};
840+
```
841+
766842
## module.noParse
767843

768844
`RegExp` `[RegExp]` `function(resource)` `string` `[string]`

src/content/configuration/node.mdx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The following Node.js options configure whether to polyfill or mock certain [Nod
1717

1818
This feature is provided by webpack's internal [`NodeStuffPlugin`](https://github.com/webpack/webpack/blob/main/lib/NodeStuffPlugin.js) plugin.
1919

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.
2121

2222
## node
2323

@@ -48,7 +48,7 @@ See [the Node.js documentation](https://nodejs.org/api/globals.html#globals_glob
4848

4949
Options:
5050

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.
5252
- `false`: Provide nothing. Code that expects this object may crash with a `ReferenceError`.
5353
- `'warn'`: Show a warning when using `global`.
5454

@@ -59,11 +59,16 @@ Options:
5959
Options:
6060

6161
- `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.
6363
- `'mock'`: The fixed value `'/index.js'`.
6464
- `'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.
6772

6873
## node.\_\_dirname
6974

@@ -72,8 +77,13 @@ Options:
7277
Options:
7378

7479
- `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.
7681
- `'mock'`: The fixed value `'/'`.
7782
- `'warn-mock'`: Use the fixed value of `'/'` but show a warning.
7883
- `'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.

src/content/configuration/output.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,17 @@ module.exports = {
508508
globalThis: true,
509509
// The environment supports ECMAScript Module syntax to import ECMAScript modules (import ... from '...').
510510
module: false,
511+
// The environment supports object method shorthand ('{ module() {} }').
512+
methodShorthand: true,
511513
// Determines if the node: prefix is generated for core module imports in environments that support it.
512514
// This is only applicable to Webpack runtime code.
513515
nodePrefixForCoreModules: false,
514516
// The environment supports optional chaining ('obj?.a' or 'obj?.()').
515517
optionalChaining: true,
516518
// The environment supports template literals.
517519
templateLiteral: true,
520+
// The environment supports `import.meta.dirname` and `import.meta.filename`.
521+
importMetaDirnameAndFilename: false,
518522
},
519523
},
520524
};
@@ -2158,7 +2162,6 @@ T> It also adds some info about tree shaking to the generated bundle.
21582162
## output.publicPath
21592163

21602164
- Type:
2161-
21622165
- `function`
21632166
- `string`
21642167

src/content/plugins/eval-source-map-dev-tool-plugin.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ The following options are supported:
3737
(pathData: PathData, assetInfo?: AssetInfo) => string;
3838
```
3939

40-
- `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.
4141
- `module` (`boolean`): Indicates whether loaders should generate source maps (defaults to `true`).
42+
- `moduleFilenameTemplate` (`string`): See [`output.devtoolModuleFilenameTemplate`](/configuration/output/#outputdevtoolmodulefilenametemplate).
4243
- `columns` (`boolean`): Indicates whether column mappings should be used (defaults to `true`).
4344
- `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.
4449

4550
T> Setting `module` and/or `columns` to `false` will yield less accurate source maps but will also improve compilation performance significantly.
4651

src/content/plugins/source-map-dev-tool-plugin.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ The following options are supported:
3838

3939
- `moduleFilenameTemplate` (`string`): See [`output.devtoolModuleFilenameTemplate`](/configuration/output/#outputdevtoolmodulefilenametemplate).
4040
- `fallbackModuleFilenameTemplate` (`string`): See link above.
41-
- `namespace` (`string`): See [`output.devtoolNamespace`](/configuration/output/#outputdevtoolnamespace).
41+
- `ignoreList` (`string|RegExp|array`): Decide whether to ignore source files that match the specified value in source maps.
4242
- `module = true` (`boolean`): Indicates whether loaders should generate source maps.
4343
- `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).
4445
- `noSources = false` (`boolean`): Prevents the source file content from being included in the source map.
4546
- `publicPath` (`string`): Emits absolute URLs with public path prefix, e.g. `https://example.com/project/`.
4647
- `fileContext` (`string`): Makes the `[file]` argument relative to this directory.

0 commit comments

Comments
 (0)