@nuxt/rspack-builder 3.17.4 → 3.17.6
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/dist/index.mjs +132 -18
- package/package.json +11 -11
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ 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
10
|
import { webpack, WebpackBarPlugin, builder, MiniCssExtractPlugin, TsCheckerPlugin } from '#builder';
|
|
@@ -17,6 +17,7 @@ import TimeFixPlugin from 'time-fix-plugin';
|
|
|
17
17
|
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin';
|
|
18
18
|
import escapeRegExp from 'escape-string-regexp';
|
|
19
19
|
import { isTest } from 'std-env';
|
|
20
|
+
import { genObjectFromRawEntries, genString } from 'knitwork';
|
|
20
21
|
import { EsbuildPlugin } from 'esbuild-loader';
|
|
21
22
|
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
22
23
|
import createResolver from 'postcss-import-resolver';
|
|
@@ -177,6 +178,123 @@ class WarningIgnorePlugin {
|
|
|
177
178
|
}
|
|
178
179
|
}
|
|
179
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
|
+
|
|
180
298
|
async function base(ctx) {
|
|
181
299
|
await applyPresets(ctx, [
|
|
182
300
|
baseAlias,
|
|
@@ -265,6 +383,9 @@ function basePlugins(ctx) {
|
|
|
265
383
|
}
|
|
266
384
|
}));
|
|
267
385
|
}
|
|
386
|
+
if (ctx.isServer && !ctx.isDev) {
|
|
387
|
+
ctx.config.plugins.push(new RollupCompatDynamicImportPlugin());
|
|
388
|
+
}
|
|
268
389
|
}
|
|
269
390
|
function baseAlias(ctx) {
|
|
270
391
|
ctx.alias = {
|
|
@@ -578,23 +699,6 @@ async function createPostcssLoadersRule(ctx) {
|
|
|
578
699
|
};
|
|
579
700
|
}
|
|
580
701
|
|
|
581
|
-
const validate = (compiler) => {
|
|
582
|
-
if (compiler.options.target !== "node") {
|
|
583
|
-
logger.warn('webpack config `target` should be "node".');
|
|
584
|
-
}
|
|
585
|
-
if (!compiler.options.externals) {
|
|
586
|
-
logger.info(
|
|
587
|
-
"It is recommended to externalize dependencies in the server build for better build performance."
|
|
588
|
-
);
|
|
589
|
-
}
|
|
590
|
-
};
|
|
591
|
-
const isJSRegExp = /\.[cm]?js(\?[^.]+)?$/;
|
|
592
|
-
const isJS = (file) => isJSRegExp.test(file);
|
|
593
|
-
const extractQueryPartJS = (file) => isJSRegExp.exec(file)?.[1];
|
|
594
|
-
const isCSSRegExp = /\.css(?:\?[^.]+)?$/;
|
|
595
|
-
const isCSS = (file) => isCSSRegExp.test(file);
|
|
596
|
-
const isHotUpdate = (file) => file.includes("hot-update");
|
|
597
|
-
|
|
598
702
|
class VueSSRClientPlugin {
|
|
599
703
|
options;
|
|
600
704
|
constructor(options) {
|
|
@@ -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/rspack-builder",
|
|
3
|
-
"version": "3.17.
|
|
3
|
+
"version": "3.17.6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/nuxt.git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@nuxt/friendly-errors-webpack-plugin": "^2.6.0",
|
|
30
|
-
"@rspack/core": "^1.
|
|
30
|
+
"@rspack/core": "^1.4.1",
|
|
31
31
|
"autoprefixer": "^10.4.21",
|
|
32
32
|
"css-loader": "^7.1.2",
|
|
33
33
|
"css-minimizer-webpack-plugin": "^7.0.2",
|
|
@@ -44,18 +44,18 @@
|
|
|
44
44
|
"ohash": "^2.0.11",
|
|
45
45
|
"pathe": "^2.0.3",
|
|
46
46
|
"pify": "^6.1.0",
|
|
47
|
-
"postcss": "^8.5.
|
|
48
|
-
"postcss-import": "^16.1.
|
|
47
|
+
"postcss": "^8.5.6",
|
|
48
|
+
"postcss-import": "^16.1.1",
|
|
49
49
|
"postcss-import-resolver": "^2.0.0",
|
|
50
50
|
"postcss-loader": "^8.1.1",
|
|
51
51
|
"postcss-url": "^10.1.3",
|
|
52
52
|
"pug-plain-loader": "^1.1.0",
|
|
53
53
|
"std-env": "^3.9.0",
|
|
54
54
|
"time-fix-plugin": "^2.0.7",
|
|
55
|
-
"ts-checker-rspack-plugin": "^1.1.
|
|
55
|
+
"ts-checker-rspack-plugin": "^1.1.4",
|
|
56
56
|
"ufo": "^1.6.1",
|
|
57
|
-
"unenv": "^2.0.0-rc.
|
|
58
|
-
"unplugin": "^2.3.
|
|
57
|
+
"unenv": "^2.0.0-rc.18",
|
|
58
|
+
"unplugin": "^2.3.5",
|
|
59
59
|
"url-loader": "^4.1.1",
|
|
60
60
|
"vue-bundle-renderer": "^2.1.1",
|
|
61
61
|
"vue-loader": "^17.4.2",
|
|
@@ -63,16 +63,16 @@
|
|
|
63
63
|
"webpack-dev-middleware": "^7.4.2",
|
|
64
64
|
"webpack-hot-middleware": "^2.26.1",
|
|
65
65
|
"webpackbar": "^7.0.0",
|
|
66
|
-
"@nuxt/kit": "3.17.
|
|
66
|
+
"@nuxt/kit": "3.17.6"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/pify": "6.1.0",
|
|
70
70
|
"@types/webpack-bundle-analyzer": "4.7.0",
|
|
71
71
|
"@types/webpack-hot-middleware": "2.25.9",
|
|
72
|
-
"rollup": "4.
|
|
72
|
+
"rollup": "4.44.1",
|
|
73
73
|
"unbuild": "3.5.0",
|
|
74
|
-
"vue": "3.5.
|
|
75
|
-
"@nuxt/schema": "3.17.
|
|
74
|
+
"vue": "3.5.17",
|
|
75
|
+
"@nuxt/schema": "3.17.6"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"vue": "^3.3.4"
|