@nuxt/rspack-builder-nightly 4.0.0-29162105.8c587084 → 4.0.0-29165109.5b7cbcb6

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.
Files changed (2) hide show
  1. package/dist/index.mjs +146 -132
  2. package/package.json +12 -12
package/dist/index.mjs CHANGED
@@ -1,14 +1,14 @@
1
1
  import pify from 'pify';
2
- import { join, resolve, normalize, dirname, isAbsolute } from 'pathe';
3
2
  import { fromNodeMiddleware, defineEventHandler, handleCors, getRequestHeader, createError, setHeader } from 'h3';
4
3
  import webpackDevMiddleware from 'webpack-dev-middleware';
5
4
  import webpackHotMiddleware from 'webpack-hot-middleware';
6
5
  import { defu } from 'defu';
7
6
  import { joinURL } from 'ufo';
8
- import { logger, importModule, useNitro, useNuxt } from '@nuxt/kit';
7
+ import { logger, useNitro, useNuxt } from '@nuxt/kit';
9
8
  import { createUnplugin } from 'unplugin';
10
9
  import MagicString from 'magic-string';
11
10
  import { webpack, WebpackBarPlugin, builder, MiniCssExtractPlugin, TsCheckerPlugin } from '#builder';
11
+ import { join, resolve, basename, 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';
@@ -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';
@@ -25,8 +26,6 @@ import VueLoaderPlugin from 'vue-loader/dist/pluginWebpack5.js';
25
26
  import { mkdir, writeFile } from 'node:fs/promises';
26
27
  import { normalizeWebpackManifest } from 'vue-bundle-renderer';
27
28
  import { hash } from 'ohash';
28
- import { glob } from 'tinyglobby';
29
- import { genSafeVariableName } from 'knitwork';
30
29
 
31
30
  const defaults = {
32
31
  globalPublicPath: "__webpack_public_path__",
@@ -179,6 +178,123 @@ class WarningIgnorePlugin {
179
178
  }
180
179
  }
181
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
+
182
298
  async function base(ctx) {
183
299
  await applyPresets(ctx, [
184
300
  baseAlias,
@@ -267,15 +383,21 @@ function basePlugins(ctx) {
267
383
  }
268
384
  }));
269
385
  }
386
+ if (ctx.isServer && !ctx.isDev) {
387
+ ctx.config.plugins.push(new RollupCompatDynamicImportPlugin());
388
+ }
270
389
  }
271
390
  function baseAlias(ctx) {
272
391
  ctx.alias = {
273
392
  "#app": ctx.options.appDir,
393
+ [basename(ctx.nuxt.options.dir.assets)]: resolve(ctx.nuxt.options.srcDir, ctx.nuxt.options.dir.assets),
274
394
  ...ctx.options.alias,
275
395
  ...ctx.alias
276
396
  };
277
397
  if (ctx.isClient) {
278
398
  ctx.alias["nitro/runtime"] = resolve(ctx.nuxt.options.buildDir, "nitro.client.mjs");
399
+ ctx.alias["#internal/nitro"] = resolve(ctx.nuxt.options.buildDir, "nitro.client.mjs");
400
+ ctx.alias["nitropack/runtime"] = resolve(ctx.nuxt.options.buildDir, "nitro.client.mjs");
279
401
  }
280
402
  }
281
403
  function baseResolve(ctx) {
@@ -580,23 +702,6 @@ async function createPostcssLoadersRule(ctx) {
580
702
  };
581
703
  }
582
704
 
583
- const validate = (compiler) => {
584
- if (compiler.options.target !== "node") {
585
- logger.warn('webpack config `target` should be "node".');
586
- }
587
- if (!compiler.options.externals) {
588
- logger.info(
589
- "It is recommended to externalize dependencies in the server build for better build performance."
590
- );
591
- }
592
- };
593
- const isJSRegExp = /\.[cm]?js(\?[^.]+)?$/;
594
- const isJS = (file) => isJSRegExp.test(file);
595
- const extractQueryPartJS = (file) => isJSRegExp.exec(file)?.[1];
596
- const isCSSRegExp = /\.css(?:\?[^.]+)?$/;
597
- const isCSS = (file) => isCSSRegExp.test(file);
598
- const isHotUpdate = (file) => file.includes("hot-update");
599
-
600
705
  class VueSSRClientPlugin {
601
706
  options;
602
707
  constructor(options) {
@@ -969,6 +1074,9 @@ function serverStandalone(ctx) {
969
1074
  ];
970
1075
  const external = /* @__PURE__ */ new Set([
971
1076
  "nitro/runtime",
1077
+ // TODO: remove in v5
1078
+ "#internal/nitro",
1079
+ "nitropack/runtime",
972
1080
  "#shared",
973
1081
  resolve(ctx.nuxt.options.rootDir, ctx.nuxt.options.dir.shared)
974
1082
  ]);
@@ -1008,92 +1116,6 @@ function serverPlugins(ctx) {
1008
1116
  }
1009
1117
  }
1010
1118
 
1011
- const PLUGIN_NAME = "dynamic-require";
1012
- const HELPER_DYNAMIC = `\0${PLUGIN_NAME}.mjs`;
1013
- const DYNAMIC_REQUIRE_RE = /import\((?:.*\+\s*)?"\.\/" ?\+(.*)\).then/g;
1014
- const BACKWARD_SLASH_RE = /\\/g;
1015
- function dynamicRequire({ dir, ignore, inline }) {
1016
- const filesToIgnore = new Set(ignore);
1017
- return {
1018
- name: PLUGIN_NAME,
1019
- transform(code, _id) {
1020
- return {
1021
- code: code.replace(
1022
- DYNAMIC_REQUIRE_RE,
1023
- `import('${HELPER_DYNAMIC}').then(r => r.default || r).then(dynamicRequire => dynamicRequire($1)).then`
1024
- ),
1025
- map: null
1026
- };
1027
- },
1028
- resolveId(id) {
1029
- return id === HELPER_DYNAMIC ? id : null;
1030
- },
1031
- // TODO: Async chunk loading over network!
1032
- // renderDynamicImport () {
1033
- // return {
1034
- // left: 'fetch(', right: ')'
1035
- // }
1036
- // },
1037
- async load(_id) {
1038
- if (_id !== HELPER_DYNAMIC) {
1039
- return null;
1040
- }
1041
- let files = [];
1042
- try {
1043
- const wpManifest = resolve(dir, "./server.manifest.json");
1044
- files = await importModule(wpManifest).then((r) => Object.keys(r.files).filter((file) => !filesToIgnore.has(file)));
1045
- } catch {
1046
- files = await glob("**/*.{cjs,mjs,js}", {
1047
- cwd: dir,
1048
- absolute: false,
1049
- ignore
1050
- });
1051
- }
1052
- const chunks = (await Promise.all(
1053
- files.map(async (id) => ({
1054
- id,
1055
- src: resolve(dir, id).replace(BACKWARD_SLASH_RE, "/"),
1056
- name: genSafeVariableName(id),
1057
- meta: await getWebpackChunkMeta(resolve(dir, id))
1058
- }))
1059
- )).filter((chunk) => chunk.meta);
1060
- return inline ? TMPL_INLINE({ chunks }) : TMPL_LAZY({ chunks });
1061
- }
1062
- };
1063
- }
1064
- async function getWebpackChunkMeta(src) {
1065
- const chunk = await importModule(src) || {};
1066
- const { __webpack_id__, __webpack_ids__, __webpack_modules__, id = __webpack_id__, ids = __webpack_ids__, modules = __webpack_modules__ } = chunk;
1067
- if (!id && !ids) {
1068
- return null;
1069
- }
1070
- return {
1071
- id,
1072
- ids,
1073
- moduleIds: Object.keys(modules || {})
1074
- };
1075
- }
1076
- function TMPL_INLINE({ chunks }) {
1077
- return `${chunks.map((i) => `import * as ${i.name} from '${i.src}'`).join("\n")}
1078
- const dynamicChunks = {
1079
- ${chunks.map((i) => ` ['${i.id}']: ${i.name}`).join(",\n")}
1080
- };
1081
-
1082
- export default function dynamicRequire(id) {
1083
- return Promise.resolve(dynamicChunks[id]);
1084
- };`;
1085
- }
1086
- function TMPL_LAZY({ chunks }) {
1087
- return `
1088
- const dynamicChunks = {
1089
- ${chunks.map((i) => ` ['${i.id}']: () => import('${i.src}')`).join(",\n")}
1090
- };
1091
-
1092
- export default function dynamicRequire(id) {
1093
- return dynamicChunks[id]();
1094
- };`;
1095
- }
1096
-
1097
1119
  const bundle = async (nuxt) => {
1098
1120
  const webpackConfigs = await Promise.all([client, ...nuxt.options.ssr ? [server] : []].map(async (preset) => {
1099
1121
  const ctx = createWebpackConfigContext(nuxt);
@@ -1103,21 +1125,13 @@ const bundle = async (nuxt) => {
1103
1125
  }));
1104
1126
  if (!nuxt.options.dev) {
1105
1127
  const nitro = useNitro();
1106
- const dynamicRequirePlugin = dynamicRequire({
1107
- dir: resolve(nuxt.options.buildDir, "dist/server"),
1108
- inline: nitro.options.node === false || nitro.options.inlineDynamicImports,
1109
- ignore: [
1110
- "client.manifest.mjs",
1111
- "server.js",
1112
- "server.cjs",
1113
- "server.mjs",
1114
- "server.manifest.mjs"
1115
- ]
1128
+ nitro.hooks.hook("rollup:before", (_nitro, config) => {
1129
+ const plugins = config.plugins;
1130
+ const existingPlugin = plugins.findIndex((i) => i && "name" in i && i.name === "dynamic-require");
1131
+ if (existingPlugin >= 0) {
1132
+ plugins.splice(existingPlugin, 1);
1133
+ }
1116
1134
  });
1117
- const prerenderRollupPlugins = nitro.options._config.rollupConfig.plugins;
1118
- const rollupPlugins = nitro.options.rollupConfig.plugins;
1119
- prerenderRollupPlugins.push(dynamicRequirePlugin);
1120
- rollupPlugins.push(dynamicRequirePlugin);
1121
1135
  }
1122
1136
  await nuxt.callHook(`${builder}:config`, webpackConfigs);
1123
1137
  const mfs = nuxt.options.dev ? createMFS() : null;
@@ -1139,7 +1153,7 @@ const bundle = async (nuxt) => {
1139
1153
  });
1140
1154
  nuxt.hook("close", async () => {
1141
1155
  for (const compiler of compilers) {
1142
- await new Promise((resolve2) => compiler.close(resolve2));
1156
+ await new Promise((resolve) => compiler.close(resolve));
1143
1157
  }
1144
1158
  });
1145
1159
  if (nuxt.options.dev) {
@@ -1193,21 +1207,21 @@ function wdmToH3Handler(devMiddleware, corsOptions) {
1193
1207
  devMiddleware: devMiddleware.context
1194
1208
  };
1195
1209
  const { req, res } = event.node;
1196
- const body = await new Promise((resolve2, reject) => {
1210
+ const body = await new Promise((resolve, reject) => {
1197
1211
  res.stream = (stream) => {
1198
- resolve2(stream);
1212
+ resolve(stream);
1199
1213
  };
1200
1214
  res.send = (data) => {
1201
- resolve2(data);
1215
+ resolve(data);
1202
1216
  };
1203
1217
  res.finish = (data) => {
1204
- resolve2(data);
1218
+ resolve(data);
1205
1219
  };
1206
1220
  devMiddleware(req, res, (err) => {
1207
1221
  if (err) {
1208
1222
  reject(err);
1209
1223
  } else {
1210
- resolve2(void 0);
1224
+ resolve(void 0);
1211
1225
  }
1212
1226
  });
1213
1227
  });
@@ -1226,9 +1240,9 @@ async function compile(compiler) {
1226
1240
  await Promise.all(compilersWatching.map((watching) => pify(watching.close.bind(watching))()));
1227
1241
  });
1228
1242
  if (compiler.options.name === "client") {
1229
- return new Promise((resolve2, reject) => {
1243
+ return new Promise((resolve, reject) => {
1230
1244
  compiler.hooks.done.tap("nuxt-dev", () => {
1231
- resolve2(null);
1245
+ resolve(null);
1232
1246
  });
1233
1247
  compiler.hooks.failed.tap("nuxt-errorlog", (err) => {
1234
1248
  reject(err);
@@ -1240,17 +1254,17 @@ async function compile(compiler) {
1240
1254
  });
1241
1255
  });
1242
1256
  }
1243
- return new Promise((resolve2, reject) => {
1257
+ return new Promise((resolve, reject) => {
1244
1258
  const watching = compiler.watch(nuxt.options.watchers.webpack, (err) => {
1245
1259
  if (err) {
1246
1260
  return reject(err);
1247
1261
  }
1248
- resolve2(null);
1262
+ resolve(null);
1249
1263
  });
1250
1264
  compilersWatching.push(watching);
1251
1265
  });
1252
1266
  }
1253
- const stats = await new Promise((resolve2, reject) => compiler.run((err, stats2) => err ? reject(err) : resolve2(stats2)));
1267
+ const stats = await new Promise((resolve, reject) => compiler.run((err, stats2) => err ? reject(err) : resolve(stats2)));
1254
1268
  if (stats.hasErrors()) {
1255
1269
  const error = new Error("Nuxt build error");
1256
1270
  error.stack = stats.toString("errors-only");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/rspack-builder-nightly",
3
- "version": "4.0.0-29162105.8c587084",
3
+ "version": "4.0.0-29165109.5b7cbcb6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -27,8 +27,8 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "@nuxt/friendly-errors-webpack-plugin": "^2.6.0",
30
- "@nuxt/kit": "npm:@nuxt/kit-nightly@4.0.0-29162105.8c587084",
31
- "@rspack/core": "^1.3.9",
30
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@4.0.0-29165109.5b7cbcb6",
31
+ "@rspack/core": "^1.3.15",
32
32
  "autoprefixer": "^10.4.21",
33
33
  "css-loader": "^7.1.2",
34
34
  "css-minimizer-webpack-plugin": "^7.0.2",
@@ -41,11 +41,11 @@
41
41
  "jiti": "^2.4.2",
42
42
  "knitwork": "^1.2.0",
43
43
  "magic-string": "^0.30.17",
44
- "memfs": "^4.17.1",
44
+ "memfs": "^4.17.2",
45
45
  "ohash": "^2.0.11",
46
46
  "pathe": "^2.0.3",
47
47
  "pify": "^6.1.0",
48
- "postcss": "^8.5.3",
48
+ "postcss": "^8.5.4",
49
49
  "postcss-import": "^16.1.0",
50
50
  "postcss-import-resolver": "^2.0.0",
51
51
  "postcss-loader": "^8.1.1",
@@ -53,11 +53,11 @@
53
53
  "pug-plain-loader": "^1.1.0",
54
54
  "std-env": "^3.9.0",
55
55
  "time-fix-plugin": "^2.0.7",
56
- "tinyglobby": "^0.2.13",
57
- "ts-checker-rspack-plugin": "^1.1.1",
56
+ "tinyglobby": "^0.2.14",
57
+ "ts-checker-rspack-plugin": "^1.1.4",
58
58
  "ufo": "^1.6.1",
59
- "unenv": "^2.0.0-rc.15",
60
- "unplugin": "^2.3.3",
59
+ "unenv": "^2.0.0-rc.17",
60
+ "unplugin": "^2.3.5",
61
61
  "url-loader": "^4.1.1",
62
62
  "vue-bundle-renderer": "^2.1.1",
63
63
  "vue-loader": "^17.4.2",
@@ -67,12 +67,12 @@
67
67
  "webpackbar": "^7.0.0"
68
68
  },
69
69
  "devDependencies": {
70
- "@nuxt/schema": "npm:@nuxt/schema-nightly@4.0.0-29162105.8c587084",
70
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@4.0.0-29165109.5b7cbcb6",
71
71
  "@types/webpack-bundle-analyzer": "4.7.0",
72
72
  "@types/webpack-hot-middleware": "2.25.9",
73
- "rollup": "4.40.2",
73
+ "rollup": "4.42.0",
74
74
  "unbuild": "3.5.0",
75
- "vue": "3.5.13"
75
+ "vue": "3.5.16"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "vue": "^3.3.4"