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/blog/2026-03-13-webpack-5-106.mdx
+47-8Lines changed: 47 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,10 +82,13 @@ module.exports = {
82
82
Webpack can now statically analyze **destructuring assignments directly from CommonJS `require`** (and `module.require`) and treat only the destructured properties as “referenced exports”, instead of conservatively assuming the whole `exports` object is used. This improves dead-code elimination in optimized builds and can reduce bundle size in codebases that still consume CommonJS modules.
83
83
84
84
**Examples**
85
+
85
86
```js
86
87
// Only `a` is considered referenced
87
88
const { a } =require("./module");
89
+
```
88
90
91
+
```js
89
92
// Also supported
90
93
const { a, b } =module.require("./module");
91
94
```
@@ -96,12 +99,12 @@ const { a, b } = module.require("./module");
96
99
97
100
This makes virtual modules behave more like real files: code such as `import "./utils"` resolves consistently instead of falling back to `compiler.context` and potentially resolving incorrectly.
98
101
99
-
`context` can be set per virtual module (inside the module definition) or as a plugin level default. It defaults to `"auto"`, which tries to infer the context from the virtual module id or path; otherwise it falls back to `compiler.context`. Conceptually, when you set `context` for a module, webpack treats that virtual module *as if it lived inside that directory* for resolving relative paths.
102
+
`context` can be set per virtual module (inside the module definition) or as a plugin level default. It defaults to `"auto"`, which tries to infer the context from the virtual module id or path; otherwise it falls back to `compiler.context`. Conceptually, when you set `context` for a module, webpack treats that virtual module _as if it lived inside that directory_ for resolving relative paths.
100
103
101
104
For example, if you define a virtual module id `virtual/table.js` with `context: path.join(__dirname, "src/components")`, then its internal `import "./utils"` is resolved as if the file were `src/components/table.js` importing `src/components/utils.js`.
102
105
103
106
```js
104
-
constpath=require("path");
107
+
constpath=require("node:path");
105
108
constwebpack=require("webpack");
106
109
107
110
module.exports= {
@@ -112,17 +115,53 @@ module.exports = {
112
115
context:"auto",
113
116
source() {
114
117
return"import { trim } from './utils'; export const button = trim('button ');";
115
-
}
118
+
},
116
119
},
117
120
"virtual/table.js": {
118
121
context:path.join(__dirname, "src/components"),
119
122
source() {
120
123
return"import { trim } from './utils'; export const table = trim('table ');";
121
-
}
122
-
}
124
+
},
125
+
},
123
126
},
124
-
{ context:"auto" }
125
-
)
126
-
]
127
+
{ context:"auto" },
128
+
),
129
+
],
127
130
};
128
131
```
132
+
133
+
## Experimental JavaScript Parsing with `oxc-parser`
134
+
135
+
Webpack now includes an example demonstrating how to replace the default JavaScript parser with **`oxc-parser`**. This integration should be considered **purely experimental** and is **not recommended for production use**.
136
+
137
+
Instead, it is intended for **development environments** or **benchmark branches**, allowing the community to experiment with alternative parsing strategies in real projects. This helps evaluate potential improvements in **parse time and build performance**, as well as identify possible **compatibility issues**.
138
+
139
+
**Example**
140
+
141
+
The following configuration limits the custom parser to `.js` files:
142
+
143
+
```js
144
+
"use strict";
145
+
146
+
constoxcParse=require("./internals/oxc-parse");
147
+
148
+
/**@type{import("webpack").Configuration}*/
149
+
module.exports= {
150
+
mode:"production",
151
+
entry:"./src/index.js",
152
+
module: {
153
+
rules: [
154
+
{
155
+
// Apply the custom parser only to JavaScript files
156
+
test:/\.js$/,
157
+
parser: {
158
+
parse: oxcParse,
159
+
},
160
+
},
161
+
],
162
+
},
163
+
};
164
+
```
165
+
166
+
You can find the full example in the webpack repository:
0 commit comments