@nuxt/rspack-builder-nightly 4.0.0-29159718.51ecdb06 → 4.0.0-29162105.8c587084

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 +132 -146
  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';
2
3
  import { fromNodeMiddleware, defineEventHandler, handleCors, getRequestHeader, createError, setHeader } from 'h3';
3
4
  import webpackDevMiddleware from 'webpack-dev-middleware';
4
5
  import webpackHotMiddleware from 'webpack-hot-middleware';
5
6
  import { defu } from 'defu';
6
7
  import { joinURL } from 'ufo';
7
- import { logger, useNitro, useNuxt } from '@nuxt/kit';
8
+ import { logger, importModule, useNitro, useNuxt } from '@nuxt/kit';
8
9
  import { createUnplugin } from 'unplugin';
9
10
  import MagicString from 'magic-string';
10
11
  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,7 +17,6 @@ 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';
21
20
  import { EsbuildPlugin } from 'esbuild-loader';
22
21
  import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
23
22
  import createResolver from 'postcss-import-resolver';
@@ -26,6 +25,8 @@ import VueLoaderPlugin from 'vue-loader/dist/pluginWebpack5.js';
26
25
  import { mkdir, writeFile } from 'node:fs/promises';
27
26
  import { normalizeWebpackManifest } from 'vue-bundle-renderer';
28
27
  import { hash } from 'ohash';
28
+ import { glob } from 'tinyglobby';
29
+ import { genSafeVariableName } from 'knitwork';
29
30
 
30
31
  const defaults = {
31
32
  globalPublicPath: "__webpack_public_path__",
@@ -178,123 +179,6 @@ class WarningIgnorePlugin {
178
179
  }
179
180
  }
180
181
 
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
-
298
182
  async function base(ctx) {
299
183
  await applyPresets(ctx, [
300
184
  baseAlias,
@@ -383,21 +267,15 @@ function basePlugins(ctx) {
383
267
  }
384
268
  }));
385
269
  }
386
- if (ctx.isServer && !ctx.isDev) {
387
- ctx.config.plugins.push(new RollupCompatDynamicImportPlugin());
388
- }
389
270
  }
390
271
  function baseAlias(ctx) {
391
272
  ctx.alias = {
392
273
  "#app": ctx.options.appDir,
393
- [basename(ctx.nuxt.options.dir.assets)]: resolve(ctx.nuxt.options.srcDir, ctx.nuxt.options.dir.assets),
394
274
  ...ctx.options.alias,
395
275
  ...ctx.alias
396
276
  };
397
277
  if (ctx.isClient) {
398
278
  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");
401
279
  }
402
280
  }
403
281
  function baseResolve(ctx) {
@@ -702,6 +580,23 @@ async function createPostcssLoadersRule(ctx) {
702
580
  };
703
581
  }
704
582
 
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
+
705
600
  class VueSSRClientPlugin {
706
601
  options;
707
602
  constructor(options) {
@@ -1074,9 +969,6 @@ function serverStandalone(ctx) {
1074
969
  ];
1075
970
  const external = /* @__PURE__ */ new Set([
1076
971
  "nitro/runtime",
1077
- // TODO: remove in v5
1078
- "#internal/nitro",
1079
- "nitropack/runtime",
1080
972
  "#shared",
1081
973
  resolve(ctx.nuxt.options.rootDir, ctx.nuxt.options.dir.shared)
1082
974
  ]);
@@ -1116,6 +1008,92 @@ function serverPlugins(ctx) {
1116
1008
  }
1117
1009
  }
1118
1010
 
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
+
1119
1097
  const bundle = async (nuxt) => {
1120
1098
  const webpackConfigs = await Promise.all([client, ...nuxt.options.ssr ? [server] : []].map(async (preset) => {
1121
1099
  const ctx = createWebpackConfigContext(nuxt);
@@ -1125,13 +1103,21 @@ const bundle = async (nuxt) => {
1125
1103
  }));
1126
1104
  if (!nuxt.options.dev) {
1127
1105
  const nitro = useNitro();
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
- }
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
+ ]
1134
1116
  });
1117
+ const prerenderRollupPlugins = nitro.options._config.rollupConfig.plugins;
1118
+ const rollupPlugins = nitro.options.rollupConfig.plugins;
1119
+ prerenderRollupPlugins.push(dynamicRequirePlugin);
1120
+ rollupPlugins.push(dynamicRequirePlugin);
1135
1121
  }
1136
1122
  await nuxt.callHook(`${builder}:config`, webpackConfigs);
1137
1123
  const mfs = nuxt.options.dev ? createMFS() : null;
@@ -1153,7 +1139,7 @@ const bundle = async (nuxt) => {
1153
1139
  });
1154
1140
  nuxt.hook("close", async () => {
1155
1141
  for (const compiler of compilers) {
1156
- await new Promise((resolve) => compiler.close(resolve));
1142
+ await new Promise((resolve2) => compiler.close(resolve2));
1157
1143
  }
1158
1144
  });
1159
1145
  if (nuxt.options.dev) {
@@ -1207,21 +1193,21 @@ function wdmToH3Handler(devMiddleware, corsOptions) {
1207
1193
  devMiddleware: devMiddleware.context
1208
1194
  };
1209
1195
  const { req, res } = event.node;
1210
- const body = await new Promise((resolve, reject) => {
1196
+ const body = await new Promise((resolve2, reject) => {
1211
1197
  res.stream = (stream) => {
1212
- resolve(stream);
1198
+ resolve2(stream);
1213
1199
  };
1214
1200
  res.send = (data) => {
1215
- resolve(data);
1201
+ resolve2(data);
1216
1202
  };
1217
1203
  res.finish = (data) => {
1218
- resolve(data);
1204
+ resolve2(data);
1219
1205
  };
1220
1206
  devMiddleware(req, res, (err) => {
1221
1207
  if (err) {
1222
1208
  reject(err);
1223
1209
  } else {
1224
- resolve(void 0);
1210
+ resolve2(void 0);
1225
1211
  }
1226
1212
  });
1227
1213
  });
@@ -1240,9 +1226,9 @@ async function compile(compiler) {
1240
1226
  await Promise.all(compilersWatching.map((watching) => pify(watching.close.bind(watching))()));
1241
1227
  });
1242
1228
  if (compiler.options.name === "client") {
1243
- return new Promise((resolve, reject) => {
1229
+ return new Promise((resolve2, reject) => {
1244
1230
  compiler.hooks.done.tap("nuxt-dev", () => {
1245
- resolve(null);
1231
+ resolve2(null);
1246
1232
  });
1247
1233
  compiler.hooks.failed.tap("nuxt-errorlog", (err) => {
1248
1234
  reject(err);
@@ -1254,17 +1240,17 @@ async function compile(compiler) {
1254
1240
  });
1255
1241
  });
1256
1242
  }
1257
- return new Promise((resolve, reject) => {
1243
+ return new Promise((resolve2, reject) => {
1258
1244
  const watching = compiler.watch(nuxt.options.watchers.webpack, (err) => {
1259
1245
  if (err) {
1260
1246
  return reject(err);
1261
1247
  }
1262
- resolve(null);
1248
+ resolve2(null);
1263
1249
  });
1264
1250
  compilersWatching.push(watching);
1265
1251
  });
1266
1252
  }
1267
- const stats = await new Promise((resolve, reject) => compiler.run((err, stats2) => err ? reject(err) : resolve(stats2)));
1253
+ const stats = await new Promise((resolve2, reject) => compiler.run((err, stats2) => err ? reject(err) : resolve2(stats2)));
1268
1254
  if (stats.hasErrors()) {
1269
1255
  const error = new Error("Nuxt build error");
1270
1256
  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-29159718.51ecdb06",
3
+ "version": "4.0.0-29162105.8c587084",
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-29159718.51ecdb06",
31
- "@rspack/core": "^1.3.15",
30
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@4.0.0-29162105.8c587084",
31
+ "@rspack/core": "^1.3.9",
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.2",
44
+ "memfs": "^4.17.1",
45
45
  "ohash": "^2.0.11",
46
46
  "pathe": "^2.0.3",
47
47
  "pify": "^6.1.0",
48
- "postcss": "^8.5.4",
48
+ "postcss": "^8.5.3",
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.14",
57
- "ts-checker-rspack-plugin": "^1.1.4",
56
+ "tinyglobby": "^0.2.13",
57
+ "ts-checker-rspack-plugin": "^1.1.1",
58
58
  "ufo": "^1.6.1",
59
- "unenv": "^2.0.0-rc.17",
60
- "unplugin": "^2.3.5",
59
+ "unenv": "^2.0.0-rc.15",
60
+ "unplugin": "^2.3.3",
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-29159718.51ecdb06",
70
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@4.0.0-29162105.8c587084",
71
71
  "@types/webpack-bundle-analyzer": "4.7.0",
72
72
  "@types/webpack-hot-middleware": "2.25.9",
73
- "rollup": "4.42.0",
73
+ "rollup": "4.40.2",
74
74
  "unbuild": "3.5.0",
75
- "vue": "3.5.16"
75
+ "vue": "3.5.13"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "vue": "^3.3.4"