@nuxt/webpack-builder 3.17.3 → 3.17.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builder.mjs +1 -0
- package/dist/index.mjs +140 -26
- package/package.json +12 -10
package/builder.mjs
CHANGED
|
@@ -2,3 +2,4 @@ export const builder = 'webpack'
|
|
|
2
2
|
export { default as webpack } from 'webpack'
|
|
3
3
|
export { default as MiniCssExtractPlugin } from 'mini-css-extract-plugin'
|
|
4
4
|
export { default as WebpackBarPlugin } from 'webpackbar'
|
|
5
|
+
export { default as TsCheckerPlugin } from 'fork-ts-checker-webpack-plugin'
|
package/dist/index.mjs
CHANGED
|
@@ -4,20 +4,20 @@ import webpackDevMiddleware from 'webpack-dev-middleware';
|
|
|
4
4
|
import webpackHotMiddleware from 'webpack-hot-middleware';
|
|
5
5
|
import { defu } from 'defu';
|
|
6
6
|
import { joinURL } from 'ufo';
|
|
7
|
-
import { logger, useNuxt } from '@nuxt/kit';
|
|
7
|
+
import { logger, useNitro, useNuxt } from '@nuxt/kit';
|
|
8
8
|
import { createUnplugin } from 'unplugin';
|
|
9
9
|
import MagicString from 'magic-string';
|
|
10
|
-
import { webpack, WebpackBarPlugin, builder, MiniCssExtractPlugin } from '#builder';
|
|
10
|
+
import { webpack, WebpackBarPlugin, builder, MiniCssExtractPlugin, TsCheckerPlugin } from '#builder';
|
|
11
11
|
import { join, resolve, normalize, dirname, isAbsolute } from 'pathe';
|
|
12
12
|
import { createFsFromVolume, Volume } from 'memfs';
|
|
13
13
|
import querystring from 'node:querystring';
|
|
14
14
|
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
|
|
15
|
-
import ForkTSCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
|
|
16
15
|
import { defineEnv } from 'unenv';
|
|
17
16
|
import TimeFixPlugin from 'time-fix-plugin';
|
|
18
17
|
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin';
|
|
19
18
|
import escapeRegExp from 'escape-string-regexp';
|
|
20
19
|
import { isTest } from 'std-env';
|
|
20
|
+
import { genObjectFromRawEntries, genString } from 'knitwork';
|
|
21
21
|
import { EsbuildPlugin } from 'esbuild-loader';
|
|
22
22
|
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
23
23
|
import createResolver from 'postcss-import-resolver';
|
|
@@ -178,6 +178,123 @@ class WarningIgnorePlugin {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
const validate = (compiler) => {
|
|
182
|
+
if (compiler.options.target !== "node") {
|
|
183
|
+
logger.warn('webpack config `target` should be "node".');
|
|
184
|
+
}
|
|
185
|
+
if (!compiler.options.externals) {
|
|
186
|
+
logger.info(
|
|
187
|
+
"It is recommended to externalize dependencies in the server build for better build performance."
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const isJSRegExp = /\.[cm]?js(\?[^.]+)?$/;
|
|
192
|
+
const isJS = (file) => isJSRegExp.test(file);
|
|
193
|
+
const extractQueryPartJS = (file) => isJSRegExp.exec(file)?.[1];
|
|
194
|
+
const isCSSRegExp = /\.css(?:\?[^.]+)?$/;
|
|
195
|
+
const isCSS = (file) => isCSSRegExp.test(file);
|
|
196
|
+
const isHotUpdate = (file) => file.includes("hot-update");
|
|
197
|
+
|
|
198
|
+
const DYNAMIC_IMPORT_RE = /import\([^)]*\+\s*__webpack_require__[^+]*\)\.then/;
|
|
199
|
+
const DYNAMIC_IMPORT_REPLACE_RE = /import\([^)]*\+\s*(__webpack_require__[^+]*)\)\.then/g;
|
|
200
|
+
const HELPER_FILENAME = "_dynamic-import-helper.mjs";
|
|
201
|
+
const HELPER_IMPORT = `import { _rollupDynamicImport } from "./${HELPER_FILENAME}";
|
|
202
|
+
`;
|
|
203
|
+
class RollupCompatDynamicImportPlugin {
|
|
204
|
+
apply(compiler) {
|
|
205
|
+
compiler.hooks.compilation.tap("RollupCompatDynamicImportPlugin", (compilation) => {
|
|
206
|
+
compilation.hooks.processAssets.tapAsync(
|
|
207
|
+
{
|
|
208
|
+
name: "RollupCompatDynamicImportPlugin",
|
|
209
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE
|
|
210
|
+
},
|
|
211
|
+
(assets, callback) => {
|
|
212
|
+
try {
|
|
213
|
+
const targetFiles = /* @__PURE__ */ new Set();
|
|
214
|
+
for (const chunk of compilation.chunks) {
|
|
215
|
+
if (chunk.canBeInitial() || chunk.hasRuntime()) {
|
|
216
|
+
for (const file of chunk.files || []) {
|
|
217
|
+
targetFiles.add(file);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
for (const [filename, asset] of Object.entries(assets)) {
|
|
222
|
+
if (!isJS(filename)) {
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (!targetFiles.has(filename)) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const source = asset.source();
|
|
229
|
+
const originalCode = typeof source === "string" ? source : source.toString();
|
|
230
|
+
if (!DYNAMIC_IMPORT_RE.test(originalCode)) {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
const transformedCode = this.transformDynamicImports(originalCode);
|
|
234
|
+
if (transformedCode !== originalCode) {
|
|
235
|
+
assets[filename] = new compiler.webpack.sources.RawSource(transformedCode);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
this.generateDynamicImportHelper(compilation);
|
|
239
|
+
callback();
|
|
240
|
+
} catch (error) {
|
|
241
|
+
callback(error);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
transformDynamicImports(source) {
|
|
248
|
+
let transformed = source;
|
|
249
|
+
let needsHelperImport = false;
|
|
250
|
+
transformed = transformed.replace(DYNAMIC_IMPORT_REPLACE_RE, (match, filename) => {
|
|
251
|
+
needsHelperImport = true;
|
|
252
|
+
return `_rollupDynamicImport(${filename}).then`;
|
|
253
|
+
});
|
|
254
|
+
if (needsHelperImport && !transformed.includes(HELPER_IMPORT)) {
|
|
255
|
+
transformed = HELPER_IMPORT + transformed;
|
|
256
|
+
}
|
|
257
|
+
return transformed;
|
|
258
|
+
}
|
|
259
|
+
generateDynamicImportHelper(compilation) {
|
|
260
|
+
const chunkFiles = [];
|
|
261
|
+
for (const chunk of compilation.chunks) {
|
|
262
|
+
if (chunk.hasRuntime()) {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
for (const filename of chunk.files) {
|
|
266
|
+
if (filename && isJS(filename)) {
|
|
267
|
+
chunkFiles.push(filename);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (chunkFiles.length === 0) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const helperContent = this.generateHelperContent(chunkFiles);
|
|
275
|
+
compilation.emitAsset(HELPER_FILENAME, new compilation.compiler.webpack.sources.RawSource(helperContent));
|
|
276
|
+
}
|
|
277
|
+
generateHelperContent(chunkFiles) {
|
|
278
|
+
return `
|
|
279
|
+
// Rollup-compatible dynamic import helper generated by webpack
|
|
280
|
+
// This helper enables rollup to consume webpack chunks directly
|
|
281
|
+
|
|
282
|
+
const chunkMap = ${genObjectFromRawEntries(chunkFiles.map((filename) => [filename, `() => import(${genString("./" + filename)})`]))}
|
|
283
|
+
|
|
284
|
+
// Dynamic import function that rollup can understand
|
|
285
|
+
export function _rollupDynamicImport(chunkId) {
|
|
286
|
+
const chunk = chunkMap[chunkId]
|
|
287
|
+
if (!chunk) {
|
|
288
|
+
return Promise.reject(new Error(\`Chunk \${chunkId} not found in chunkMap. Available chunks: \${Object.keys(chunkMap).join(', ')}\`))
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Use actual dynamic import for the chunk
|
|
292
|
+
return chunk()
|
|
293
|
+
}
|
|
294
|
+
`;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
181
298
|
async function base(ctx) {
|
|
182
299
|
await applyPresets(ctx, [
|
|
183
300
|
baseAlias,
|
|
@@ -266,6 +383,9 @@ function basePlugins(ctx) {
|
|
|
266
383
|
}
|
|
267
384
|
}));
|
|
268
385
|
}
|
|
386
|
+
if (ctx.isServer && !ctx.isDev) {
|
|
387
|
+
ctx.config.plugins.push(new RollupCompatDynamicImportPlugin());
|
|
388
|
+
}
|
|
269
389
|
}
|
|
270
390
|
function baseAlias(ctx) {
|
|
271
391
|
ctx.alias = {
|
|
@@ -579,23 +699,6 @@ async function createPostcssLoadersRule(ctx) {
|
|
|
579
699
|
};
|
|
580
700
|
}
|
|
581
701
|
|
|
582
|
-
const validate = (compiler) => {
|
|
583
|
-
if (compiler.options.target !== "node") {
|
|
584
|
-
logger.warn('webpack config `target` should be "node".');
|
|
585
|
-
}
|
|
586
|
-
if (!compiler.options.externals) {
|
|
587
|
-
logger.info(
|
|
588
|
-
"It is recommended to externalize dependencies in the server build for better build performance."
|
|
589
|
-
);
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
const isJSRegExp = /\.[cm]?js(\?[^.]+)?$/;
|
|
593
|
-
const isJS = (file) => isJSRegExp.test(file);
|
|
594
|
-
const extractQueryPartJS = (file) => isJSRegExp.exec(file)?.[1];
|
|
595
|
-
const isCSSRegExp = /\.css(?:\?[^.]+)?$/;
|
|
596
|
-
const isCSS = (file) => isCSSRegExp.test(file);
|
|
597
|
-
const isHotUpdate = (file) => file.includes("hot-update");
|
|
598
|
-
|
|
599
702
|
class VueSSRClientPlugin {
|
|
600
703
|
options;
|
|
601
704
|
constructor(options) {
|
|
@@ -889,7 +992,7 @@ function clientPlugins(ctx) {
|
|
|
889
992
|
}
|
|
890
993
|
if (!ctx.nuxt.options.ssr) {
|
|
891
994
|
if (!ctx.nuxt.options.test && (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev)) {
|
|
892
|
-
ctx.config.plugins.push(new
|
|
995
|
+
ctx.config.plugins.push(new TsCheckerPlugin({
|
|
893
996
|
logger
|
|
894
997
|
}));
|
|
895
998
|
}
|
|
@@ -966,13 +1069,14 @@ function serverStandalone(ctx) {
|
|
|
966
1069
|
"#",
|
|
967
1070
|
...ctx.options.build.transpile
|
|
968
1071
|
];
|
|
969
|
-
const external = [
|
|
1072
|
+
const external = /* @__PURE__ */ new Set([
|
|
970
1073
|
"#internal/nitro",
|
|
971
1074
|
"#shared",
|
|
972
1075
|
resolve(ctx.nuxt.options.rootDir, ctx.nuxt.options.dir.shared)
|
|
973
|
-
];
|
|
1076
|
+
]);
|
|
974
1077
|
if (!ctx.nuxt.options.dev) {
|
|
975
|
-
external.
|
|
1078
|
+
external.add("#internal/nuxt/paths");
|
|
1079
|
+
external.add("#app-manifest");
|
|
976
1080
|
}
|
|
977
1081
|
if (!Array.isArray(ctx.config.externals)) {
|
|
978
1082
|
return;
|
|
@@ -981,7 +1085,7 @@ function serverStandalone(ctx) {
|
|
|
981
1085
|
if (!request) {
|
|
982
1086
|
return cb(void 0, false);
|
|
983
1087
|
}
|
|
984
|
-
if (external.
|
|
1088
|
+
if (external.has(request)) {
|
|
985
1089
|
return cb(void 0, true);
|
|
986
1090
|
}
|
|
987
1091
|
if (request[0] === "." || isAbsolute(request) || inline.find((prefix) => typeof prefix === "string" && request.startsWith(prefix)) || assetPattern.test(request)) {
|
|
@@ -999,7 +1103,7 @@ function serverPlugins(ctx) {
|
|
|
999
1103
|
}));
|
|
1000
1104
|
}
|
|
1001
1105
|
if (!ctx.nuxt.options.test && (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev)) {
|
|
1002
|
-
ctx.config.plugins.push(new
|
|
1106
|
+
ctx.config.plugins.push(new TsCheckerPlugin({
|
|
1003
1107
|
logger
|
|
1004
1108
|
}));
|
|
1005
1109
|
}
|
|
@@ -1012,6 +1116,16 @@ const bundle = async (nuxt) => {
|
|
|
1012
1116
|
await applyPresets(ctx, preset);
|
|
1013
1117
|
return ctx.config;
|
|
1014
1118
|
}));
|
|
1119
|
+
if (!nuxt.options.dev) {
|
|
1120
|
+
const nitro = useNitro();
|
|
1121
|
+
nitro.hooks.hook("rollup:before", (_nitro, config) => {
|
|
1122
|
+
const plugins = config.plugins;
|
|
1123
|
+
const existingPlugin = plugins.findIndex((i) => i && "name" in i && i.name === "dynamic-require");
|
|
1124
|
+
if (existingPlugin >= 0) {
|
|
1125
|
+
plugins.splice(existingPlugin, 1);
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1015
1129
|
await nuxt.callHook(`${builder}:config`, webpackConfigs);
|
|
1016
1130
|
const mfs = nuxt.options.dev ? createMFS() : null;
|
|
1017
1131
|
for (const config of webpackConfigs) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/webpack-builder",
|
|
3
|
-
"version": "3.17.
|
|
3
|
+
"version": "3.17.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/nuxt.git",
|
|
@@ -38,13 +38,14 @@
|
|
|
38
38
|
"fork-ts-checker-webpack-plugin": "^9.1.0",
|
|
39
39
|
"h3": "^1.15.3",
|
|
40
40
|
"jiti": "^2.4.2",
|
|
41
|
+
"knitwork": "^1.2.0",
|
|
41
42
|
"magic-string": "^0.30.17",
|
|
42
|
-
"memfs": "^4.17.
|
|
43
|
+
"memfs": "^4.17.2",
|
|
43
44
|
"mini-css-extract-plugin": "^2.9.2",
|
|
44
45
|
"ohash": "^2.0.11",
|
|
45
46
|
"pathe": "^2.0.3",
|
|
46
47
|
"pify": "^6.1.0",
|
|
47
|
-
"postcss": "^8.5.
|
|
48
|
+
"postcss": "^8.5.4",
|
|
48
49
|
"postcss-import": "^16.1.0",
|
|
49
50
|
"postcss-import-resolver": "^2.0.0",
|
|
50
51
|
"postcss-loader": "^8.1.1",
|
|
@@ -53,26 +54,27 @@
|
|
|
53
54
|
"std-env": "^3.9.0",
|
|
54
55
|
"time-fix-plugin": "^2.0.7",
|
|
55
56
|
"ufo": "^1.6.1",
|
|
56
|
-
"unenv": "^2.0.0-rc.
|
|
57
|
-
"unplugin": "^2.3.
|
|
57
|
+
"unenv": "^2.0.0-rc.17",
|
|
58
|
+
"unplugin": "^2.3.5",
|
|
58
59
|
"url-loader": "^4.1.1",
|
|
59
60
|
"vue-bundle-renderer": "^2.1.1",
|
|
60
61
|
"vue-loader": "^17.4.2",
|
|
61
|
-
"webpack": "^5.99.
|
|
62
|
+
"webpack": "^5.99.9",
|
|
62
63
|
"webpack-bundle-analyzer": "^4.10.2",
|
|
63
64
|
"webpack-dev-middleware": "^7.4.2",
|
|
64
65
|
"webpack-hot-middleware": "^2.26.1",
|
|
65
66
|
"webpackbar": "^7.0.0",
|
|
66
|
-
"@nuxt/kit": "3.17.
|
|
67
|
+
"@nuxt/kit": "3.17.5"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
|
-
"@rspack/core": "1.3.
|
|
70
|
+
"@rspack/core": "1.3.13",
|
|
70
71
|
"@types/pify": "6.1.0",
|
|
71
72
|
"@types/webpack-bundle-analyzer": "4.7.0",
|
|
72
73
|
"@types/webpack-hot-middleware": "2.25.9",
|
|
74
|
+
"rollup": "4.41.1",
|
|
73
75
|
"unbuild": "3.5.0",
|
|
74
|
-
"vue": "3.5.
|
|
75
|
-
"@nuxt/schema": "3.17.
|
|
76
|
+
"vue": "3.5.16",
|
|
77
|
+
"@nuxt/schema": "3.17.5"
|
|
76
78
|
},
|
|
77
79
|
"peerDependencies": {
|
|
78
80
|
"vue": "^3.3.4"
|