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
-[Better Control of Source Maps in `devtool`](#better-control-of-source-maps-in-devtool)
14
16
-[Cleaner ESM output for Node.js and modern builds](#cleaner-esm-output-for-nodejs-and-modern-builds)
@@ -41,6 +43,42 @@ For more information on reporting security vulnerabilities,
41
43
see the [Webpack Security Policy](https://github.com/webpack/webpack/security/policy)
42
44
.
43
45
46
+
## `tsconfig.json` Alias Resolution Without Requiring plugins
47
+
48
+
Module resolution can be configured to read `compilerOptions.baseUrl` and `compilerOptions.paths` from `tsconfig.json` and apply those aliases when resolving imports. As a result, it is no longer necessary to install and configure the external `tsconfig-paths-webpack-plugin` just to make TypeScript path aliases work during bundling.
49
+
50
+
In the webpack configuration, the `resolve.tsconfig` option is used to specify which tsconfig file should be used as the source (which is also useful in monorepos or setups with multiple tsconfig files):
51
+
52
+
```js
53
+
// webpack.config.js
54
+
module.exports= {
55
+
resolve: {
56
+
tsconfig:"./tsconfig.json", // Can be `false` (disabled), `true` (use the default tsconfig.json), a path to a `tsconfig.json` file, or an object with configFile and references options.
57
+
},
58
+
};
59
+
```
60
+
61
+
Example of aliases in tsconfig.json:
62
+
63
+
```json
64
+
{
65
+
"compilerOptions": {
66
+
"baseUrl": ".",
67
+
"paths": {
68
+
"@/*": ["src/*"]
69
+
}
70
+
}
71
+
}
72
+
```
73
+
74
+
And then in the code:
75
+
76
+
```ts
77
+
importButtonfrom"@/components/Button";
78
+
```
79
+
80
+
This way, `@/components/Button` can be resolved according to the rules defined in `tsconfig.json`, avoiding the need to duplicate aliases in `resolve.alias` and reducing discrepancies between what TypeScript understands and what the bundler resolves.
81
+
44
82
## Automatic Module Resolution for Web Workers
45
83
46
84
When importing a package specifically to be used in a Web Worker in Webpack, module resolution can prioritize files like `index.worker.js` over `index.js` when using [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) defined in the `exports` field of `package.json`.
@@ -90,6 +128,19 @@ if (React.useId) {
90
128
}
91
129
```
92
130
131
+
## Support `import.defer()` for Context Module
132
+
133
+
Webpack now supports `import.defer()` even when the import is a context module (that is, when the import path is built dynamically and webpack needs to include a set of possible files). In practice, this makes it much easier to defer the loading of a module selected at runtime, even when that module comes from a dynamic expression pointing to a directory. This enables patterns like “choose between a.js or b.js and load it only when needed”, with webpack generating the appropriate context so that import.defer() works correctly.
134
+
135
+
{/* eslint-disable */}
136
+
137
+
```text
138
+
constfile=Math.random() >0.5?"a.js":"b.js";
139
+
import.defer("./dir/" + file);
140
+
```
141
+
142
+
{/* eslint-enabled */}
143
+
93
144
## Preserving Custom `import.meta` Properties
94
145
95
146
Webpack now preserves custom `import.meta` properties during bundling when [`output.module`](/configuration/output/#outputmodule) is enabled. Previously, Webpack would remove any unknown `import.meta` properties (such as `import.meta.customProp`), causing the loss of contextual or tool-specific information in the build.
0 commit comments