@nuxt/webpack-builder 3.14.1592 → 3.15.1

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 (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.mjs +15 -293
  3. package/package.json +13 -17
package/README.md CHANGED
@@ -109,7 +109,7 @@ Follow the docs to [Set Up Your Local Development Environment](https://nuxt.com/
109
109
  ## <a name="follow-us">🔗 Follow Us</a>
110
110
 
111
111
  <p valign="center">
112
- <a href="https://go.nuxt.com/discord"><img width="20px" src="https://github.com/nuxt/nuxt/tree/main/.github/assets/discord.svg" alt="Discord"></a>&nbsp;&nbsp;<a href="https://go.nuxt.com/x"><img width="20px" src="https://github.com/nuxt/nuxt/tree/main/.github/assets/twitter.svg" alt="Twitter"></a>&nbsp;&nbsp;<a href="https://go.nuxt.com/github"><img width="20px" src="https://github.com/nuxt/nuxt/tree/main/.github/assets/github.svg" alt="GitHub"></a>
112
+ <a href="https://go.nuxt.com/discord"><img width="20px" src="https://github.com/nuxt/nuxt/tree/main/.github/assets/discord.svg" alt="Discord"></a>&nbsp;&nbsp;<a href="https://go.nuxt.com/x"><img width="20px" src="https://github.com/nuxt/nuxt/tree/main/.github/assets/twitter.svg" alt="Twitter"></a>&nbsp;&nbsp;<a href="https://go.nuxt.com/github"><img width="20px" src="https://github.com/nuxt/nuxt/tree/main/.github/assets/github.svg" alt="GitHub"></a>&nbsp;&nbsp;<a href="https://go.nuxt.com/bluesky"><img width="20px" src="https://github.com/nuxt/nuxt/tree/main/.github/assets/bluesky.svg" alt="Bluesky"></a>
113
113
  </p>
114
114
 
115
115
  ## <a name="license">⚖️ License</a>
package/dist/index.mjs CHANGED
@@ -3,25 +3,20 @@ import { fromNodeMiddleware, defineEventHandler } from 'h3';
3
3
  import webpackDevMiddleware from 'webpack-dev-middleware';
4
4
  import webpackHotMiddleware from 'webpack-hot-middleware';
5
5
  import { defu } from 'defu';
6
- import { parseURL, parseQuery, joinURL } from 'ufo';
6
+ import { joinURL } from 'ufo';
7
7
  import { logger, useNuxt } from '@nuxt/kit';
8
- import { pathToFileURL } from 'node:url';
9
8
  import { createUnplugin } from 'unplugin';
10
- import { isAbsolute, relative, join, resolve, normalize, dirname } from 'pathe';
11
- import { walk } from 'estree-walker';
12
9
  import MagicString from 'magic-string';
13
- import { hash } from 'ohash';
14
- import escapeRE from 'escape-string-regexp';
15
- import { findStaticImports, parseStaticImport } from 'mlly';
16
10
  import { webpack, WebpackBarPlugin, builder, MiniCssExtractPlugin } from '#builder';
11
+ import { join, resolve, normalize, dirname, isAbsolute } from 'pathe';
17
12
  import { createFsFromVolume, Volume } from 'memfs';
18
13
  import querystring from 'node:querystring';
19
14
  import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
20
15
  import ForkTSCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
21
16
  import { env, nodeless } from 'unenv';
22
- import { cloneDeep } from 'lodash-es';
23
17
  import TimeFixPlugin from 'time-fix-plugin';
24
18
  import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin';
19
+ import escapeRegExp from 'escape-string-regexp';
25
20
  import { isTest } from 'std-env';
26
21
  import { EsbuildPlugin } from 'esbuild-loader';
27
22
  import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
@@ -30,246 +25,7 @@ import { createJiti } from 'jiti';
30
25
  import VueLoaderPlugin from 'vue-loader/dist/pluginWebpack5.js';
31
26
  import { mkdir, writeFile } from 'node:fs/promises';
32
27
  import { normalizeWebpackManifest } from 'vue-bundle-renderer';
33
-
34
- function matchWithStringOrRegex(value, matcher) {
35
- if (typeof matcher === "string") {
36
- return value === matcher;
37
- } else if (matcher instanceof RegExp) {
38
- return matcher.test(value);
39
- }
40
- return false;
41
- }
42
-
43
- var __defProp$4 = Object.defineProperty;
44
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
45
- var __publicField$4 = (obj, key, value) => {
46
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
47
- return value;
48
- };
49
- const stringTypes = ["Literal", "TemplateLiteral"];
50
- const NUXT_LIB_RE = /node_modules\/(?:nuxt|nuxt3|nuxt-nightly)\//;
51
- const SUPPORTED_EXT_RE = /\.(?:m?[jt]sx?|vue)/;
52
- const SCRIPT_RE = /(?<=<script[^>]*>)[\s\S]*?(?=<\/script>)/i;
53
- const composableKeysPlugin = createUnplugin((options) => {
54
- const composableMeta = {};
55
- const composableLengths = /* @__PURE__ */ new Set();
56
- const keyedFunctions = /* @__PURE__ */ new Set();
57
- for (const { name, ...meta } of options.composables) {
58
- composableMeta[name] = meta;
59
- keyedFunctions.add(name);
60
- composableLengths.add(meta.argumentLength);
61
- }
62
- const maxLength = Math.max(...composableLengths);
63
- const KEYED_FUNCTIONS_RE = new RegExp(`\\b(${[...keyedFunctions].map((f) => escapeRE(f)).join("|")})\\b`);
64
- return {
65
- name: "nuxt:composable-keys",
66
- enforce: "post",
67
- transformInclude(id) {
68
- const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href));
69
- return !NUXT_LIB_RE.test(pathname) && SUPPORTED_EXT_RE.test(pathname) && parseQuery(search).type !== "style" && !parseQuery(search).macro;
70
- },
71
- transform(code, id) {
72
- if (!KEYED_FUNCTIONS_RE.test(code)) {
73
- return;
74
- }
75
- const { 0: script = code, index: codeIndex = 0 } = code.match(SCRIPT_RE) || { index: 0, 0: code };
76
- const s = new MagicString(code);
77
- let imports;
78
- let count = 0;
79
- const relativeID = isAbsolute(id) ? relative(options.rootDir, id) : id;
80
- const { pathname: relativePathname } = parseURL(relativeID);
81
- const ast = this.parse(script, {
82
- sourceType: "module",
83
- ecmaVersion: "latest"
84
- });
85
- let scopeTracker = new ScopeTracker();
86
- const varCollector = new ScopedVarsCollector();
87
- walk(ast, {
88
- enter(_node) {
89
- if (_node.type === "BlockStatement") {
90
- scopeTracker.enterScope();
91
- varCollector.refresh(scopeTracker.curScopeKey);
92
- } else if (_node.type === "FunctionDeclaration" && _node.id) {
93
- varCollector.addVar(_node.id.name);
94
- } else if (_node.type === "VariableDeclarator") {
95
- varCollector.collect(_node.id);
96
- }
97
- },
98
- leave(_node) {
99
- if (_node.type === "BlockStatement") {
100
- scopeTracker.leaveScope();
101
- varCollector.refresh(scopeTracker.curScopeKey);
102
- }
103
- }
104
- });
105
- scopeTracker = new ScopeTracker();
106
- walk(ast, {
107
- enter(_node) {
108
- if (_node.type === "BlockStatement") {
109
- scopeTracker.enterScope();
110
- }
111
- if (_node.type !== "CallExpression" || _node.callee.type !== "Identifier") {
112
- return;
113
- }
114
- const node = _node;
115
- const name = "name" in node.callee && node.callee.name;
116
- if (!name || !keyedFunctions.has(name) || node.arguments.length >= maxLength) {
117
- return;
118
- }
119
- imports = imports || detectImportNames(script, composableMeta);
120
- if (imports.has(name)) {
121
- return;
122
- }
123
- const meta = composableMeta[name];
124
- if (varCollector.hasVar(scopeTracker.curScopeKey, name)) {
125
- let skip = true;
126
- if (meta.source) {
127
- skip = !matchWithStringOrRegex(relativePathname, meta.source);
128
- }
129
- if (skip) {
130
- return;
131
- }
132
- }
133
- if (node.arguments.length >= meta.argumentLength) {
134
- return;
135
- }
136
- switch (name) {
137
- case "useState":
138
- if (stringTypes.includes(node.arguments[0]?.type)) {
139
- return;
140
- }
141
- break;
142
- case "useFetch":
143
- case "useLazyFetch":
144
- if (stringTypes.includes(node.arguments[1]?.type)) {
145
- return;
146
- }
147
- break;
148
- case "useAsyncData":
149
- case "useLazyAsyncData":
150
- if (stringTypes.includes(node.arguments[0]?.type) || stringTypes.includes(node.arguments[node.arguments.length - 1]?.type)) {
151
- return;
152
- }
153
- break;
154
- }
155
- const newCode = code.slice(codeIndex + node.start, codeIndex + node.end - 1).trim();
156
- const endsWithComma = newCode[newCode.length - 1] === ",";
157
- s.appendLeft(
158
- codeIndex + node.end - 1,
159
- (node.arguments.length && !endsWithComma ? ", " : "") + "'$" + hash(`${relativeID}-${++count}`) + "'"
160
- );
161
- },
162
- leave(_node) {
163
- if (_node.type === "BlockStatement") {
164
- scopeTracker.leaveScope();
165
- }
166
- }
167
- });
168
- if (s.hasChanged()) {
169
- return {
170
- code: s.toString(),
171
- map: options.sourcemap ? s.generateMap({ hires: true }) : void 0
172
- };
173
- }
174
- }
175
- };
176
- });
177
- class ScopeTracker {
178
- constructor() {
179
- // the top of the stack is not a part of current key, it is used for next level
180
- __publicField$4(this, "scopeIndexStack");
181
- __publicField$4(this, "curScopeKey");
182
- this.scopeIndexStack = [0];
183
- this.curScopeKey = "";
184
- }
185
- getKey() {
186
- return this.scopeIndexStack.slice(0, -1).join("-");
187
- }
188
- enterScope() {
189
- this.scopeIndexStack.push(0);
190
- this.curScopeKey = this.getKey();
191
- }
192
- leaveScope() {
193
- this.scopeIndexStack.pop();
194
- this.curScopeKey = this.getKey();
195
- this.scopeIndexStack[this.scopeIndexStack.length - 1]++;
196
- }
197
- }
198
- class ScopedVarsCollector {
199
- constructor() {
200
- __publicField$4(this, "curScopeKey");
201
- __publicField$4(this, "all");
202
- this.all = /* @__PURE__ */ new Map();
203
- this.curScopeKey = "";
204
- }
205
- refresh(scopeKey) {
206
- this.curScopeKey = scopeKey;
207
- }
208
- addVar(name) {
209
- let vars = this.all.get(this.curScopeKey);
210
- if (!vars) {
211
- vars = /* @__PURE__ */ new Set();
212
- this.all.set(this.curScopeKey, vars);
213
- }
214
- vars.add(name);
215
- }
216
- hasVar(scopeKey, name) {
217
- const indices = scopeKey.split("-").map(Number);
218
- for (let i = indices.length; i >= 0; i--) {
219
- if (this.all.get(indices.slice(0, i).join("-"))?.has(name)) {
220
- return true;
221
- }
222
- }
223
- return false;
224
- }
225
- collect(n) {
226
- const t = n.type;
227
- if (t === "Identifier") {
228
- this.addVar(n.name);
229
- } else if (t === "RestElement") {
230
- this.collect(n.argument);
231
- } else if (t === "AssignmentPattern") {
232
- this.collect(n.left);
233
- } else if (t === "ArrayPattern") {
234
- n.elements.forEach((e) => e && this.collect(e));
235
- } else if (t === "ObjectPattern") {
236
- n.properties.forEach((p) => {
237
- if (p.type === "RestElement") {
238
- this.collect(p);
239
- } else {
240
- this.collect(p.value);
241
- }
242
- });
243
- }
244
- }
245
- }
246
- const NUXT_IMPORT_RE = /nuxt|#app|#imports/;
247
- function detectImportNames(code, composableMeta) {
248
- const names = /* @__PURE__ */ new Set();
249
- function addName(name, specifier) {
250
- const source = composableMeta[name]?.source;
251
- if (source && matchWithStringOrRegex(specifier, source)) {
252
- return;
253
- }
254
- names.add(name);
255
- }
256
- for (const i of findStaticImports(code)) {
257
- if (NUXT_IMPORT_RE.test(i.specifier)) {
258
- continue;
259
- }
260
- const { namedImports = {}, defaultImport, namespacedImport } = parseStaticImport(i);
261
- for (const name in namedImports) {
262
- addName(namedImports[name], i.specifier);
263
- }
264
- if (defaultImport) {
265
- addName(defaultImport, i.specifier);
266
- }
267
- if (namespacedImport) {
268
- addName(namespacedImport, i.specifier);
269
- }
270
- }
271
- return names;
272
- }
28
+ import { hash } from 'ohash';
273
29
 
274
30
  const defaults = {
275
31
  globalPublicPath: "__webpack_public_path__",
@@ -297,16 +53,9 @@ ${options.globalPublicPath} = buildAssetsURL();
297
53
  };
298
54
  });
299
55
 
300
- var __defProp$3 = Object.defineProperty;
301
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
302
- var __publicField$3 = (obj, key, value) => {
303
- __defNormalProp$3(obj, key + "" , value);
304
- return value;
305
- };
306
56
  const pluginName = "ChunkErrorPlugin";
307
57
  class ChunkErrorPlugin {
308
- constructor() {
309
- __publicField$3(this, "script", `
58
+ script = `
310
59
  if (typeof ${webpack.RuntimeGlobals.require} !== "undefined") {
311
60
  var _ensureChunk = ${webpack.RuntimeGlobals.ensureChunk};
312
61
  ${webpack.RuntimeGlobals.ensureChunk} = function (chunkId) {
@@ -317,8 +66,7 @@ if (typeof ${webpack.RuntimeGlobals.require} !== "undefined") {
317
66
  throw error
318
67
  });
319
68
  };
320
- };`);
321
- }
69
+ };`;
322
70
  apply(compiler) {
323
71
  compiler.hooks.thisCompilation.tap(
324
72
  pluginName,
@@ -379,9 +127,6 @@ function fileName(ctx, key) {
379
127
  }
380
128
  return fileName2;
381
129
  }
382
- function getWebpackConfig(ctx) {
383
- return cloneDeep(ctx.config);
384
- }
385
130
 
386
131
  function assets(ctx) {
387
132
  ctx.config.module.rules.push(
@@ -418,15 +163,9 @@ function assets(ctx) {
418
163
  );
419
164
  }
420
165
 
421
- var __defProp$2 = Object.defineProperty;
422
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
423
- var __publicField$2 = (obj, key, value) => {
424
- __defNormalProp$2(obj, key + "" , value);
425
- return value;
426
- };
427
166
  class WarningIgnorePlugin {
167
+ filter;
428
168
  constructor(filter) {
429
- __publicField$2(this, "filter");
430
169
  this.filter = filter;
431
170
  }
432
171
  apply(compiler) {
@@ -446,7 +185,7 @@ async function base(ctx) {
446
185
  ]);
447
186
  }
448
187
  function baseConfig(ctx) {
449
- ctx.config = {
188
+ ctx.config = defu({}, {
450
189
  name: ctx.name,
451
190
  entry: { app: [resolve(ctx.options.appDir, ctx.options.experimental.asyncEntry ? "entry.async" : "entry")] },
452
191
  module: { rules: [] },
@@ -464,7 +203,7 @@ function baseConfig(ctx) {
464
203
  output: getOutput(ctx),
465
204
  stats: statsMap[ctx.nuxt.options.logLevel] ?? statsMap.info,
466
205
  ...ctx.config
467
- };
206
+ });
468
207
  }
469
208
  function basePlugins(ctx) {
470
209
  ctx.config.plugins = ctx.config.plugins || [];
@@ -565,7 +304,7 @@ function baseTranspile(ctx) {
565
304
  }
566
305
  }
567
306
  if (typeof pattern === "string") {
568
- transpile.push(new RegExp(escapeRE(normalize(pattern))));
307
+ transpile.push(new RegExp(escapeRegExp(normalize(pattern))));
569
308
  } else if (pattern instanceof RegExp) {
570
309
  transpile.push(pattern);
571
310
  }
@@ -854,15 +593,9 @@ const isCSSRegExp = /\.css(?:\?[^.]+)?$/;
854
593
  const isCSS = (file) => isCSSRegExp.test(file);
855
594
  const isHotUpdate = (file) => file.includes("hot-update");
856
595
 
857
- var __defProp$1 = Object.defineProperty;
858
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
859
- var __publicField$1 = (obj, key, value) => {
860
- __defNormalProp$1(obj, key + "" , value);
861
- return value;
862
- };
863
596
  class VueSSRClientPlugin {
597
+ options;
864
598
  constructor(options) {
865
- __publicField$1(this, "options");
866
599
  this.options = Object.assign({
867
600
  filename: null
868
601
  }, options);
@@ -896,7 +629,7 @@ class VueSSRClientPlugin {
896
629
  }
897
630
  if (isFileJS) {
898
631
  const componentHash = hash(chunkNames.join("|"));
899
- const map = assetsMapping[componentHash] || (assetsMapping[componentHash] = []);
632
+ const map = assetsMapping[componentHash] ||= [];
900
633
  map.push(file);
901
634
  }
902
635
  }
@@ -962,16 +695,10 @@ class VueSSRClientPlugin {
962
695
  }
963
696
  }
964
697
 
965
- var __defProp = Object.defineProperty;
966
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
967
- var __publicField = (obj, key, value) => {
968
- __defNormalProp(obj, key + "" , value);
969
- return value;
970
- };
971
698
  const JS_MAP_RE = /\.js\.map$/;
972
699
  class VueSSRServerPlugin {
700
+ options;
973
701
  constructor(options = {}) {
974
- __publicField(this, "options");
975
702
  this.options = Object.assign({
976
703
  filename: null
977
704
  }, options);
@@ -1241,7 +968,7 @@ function serverStandalone(ctx) {
1241
968
  resolve(ctx.nuxt.options.rootDir, ctx.nuxt.options.dir.shared)
1242
969
  ];
1243
970
  if (!ctx.nuxt.options.dev) {
1244
- external.push("#internal/nuxt/paths");
971
+ external.push("#internal/nuxt/paths", "#app-manifest");
1245
972
  }
1246
973
  if (!Array.isArray(ctx.config.externals)) {
1247
974
  return;
@@ -1279,7 +1006,7 @@ const bundle = async (nuxt) => {
1279
1006
  const ctx = createWebpackConfigContext(nuxt);
1280
1007
  ctx.userConfig = defu(nuxt.options.webpack[`$${preset.name}`], ctx.userConfig);
1281
1008
  await applyPresets(ctx, preset);
1282
- return getWebpackConfig(ctx);
1009
+ return ctx.config;
1283
1010
  }));
1284
1011
  await nuxt.callHook(`${builder}:config`, webpackConfigs);
1285
1012
  const mfs = nuxt.options.dev ? createMFS() : null;
@@ -1290,11 +1017,6 @@ const bundle = async (nuxt) => {
1290
1017
  if (config.name === "client" && nuxt.options.experimental.emitRouteChunkError && nuxt.options.builder !== "@nuxt/rspack-builder") {
1291
1018
  config.plugins.push(new ChunkErrorPlugin());
1292
1019
  }
1293
- config.plugins.push(composableKeysPlugin.webpack({
1294
- sourcemap: !!nuxt.options.sourcemap[config.name],
1295
- rootDir: nuxt.options.rootDir,
1296
- composables: nuxt.options.optimization.keyedComposables
1297
- }));
1298
1020
  }
1299
1021
  await nuxt.callHook(`${builder}:configResolved`, webpackConfigs);
1300
1022
  const compilers = webpackConfigs.map((config) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/webpack-builder",
3
- "version": "3.14.1592",
3
+ "version": "3.15.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -34,19 +34,15 @@
34
34
  "defu": "^6.1.4",
35
35
  "esbuild-loader": "^4.2.2",
36
36
  "escape-string-regexp": "^5.0.0",
37
- "estree-walker": "^3.0.3",
38
37
  "file-loader": "^6.2.0",
39
38
  "fork-ts-checker-webpack-plugin": "^9.0.2",
40
39
  "h3": "^1.13.0",
41
- "hash-sum": "^2.0.0",
42
- "jiti": "^2.4.0",
43
- "lodash-es": "4.17.21",
44
- "magic-string": "^0.30.13",
45
- "memfs": "^4.14.0",
40
+ "jiti": "^2.4.2",
41
+ "magic-string": "^0.30.17",
42
+ "memfs": "^4.14.1",
46
43
  "mini-css-extract-plugin": "^2.9.2",
47
- "mlly": "^1.7.3",
48
44
  "ohash": "^1.1.4",
49
- "pathe": "^1.1.2",
45
+ "pathe": "^2.0.0",
50
46
  "pify": "^6.1.0",
51
47
  "postcss": "^8.4.49",
52
48
  "postcss-import": "^16.1.0",
@@ -58,7 +54,7 @@
58
54
  "time-fix-plugin": "^2.0.7",
59
55
  "ufo": "^1.5.4",
60
56
  "unenv": "^1.10.0",
61
- "unplugin": "^1.16.0",
57
+ "unplugin": "^2.1.2",
62
58
  "url-loader": "^4.1.1",
63
59
  "vue-bundle-renderer": "^2.1.1",
64
60
  "vue-loader": "^17.4.2",
@@ -67,24 +63,24 @@
67
63
  "webpack-dev-middleware": "^7.4.2",
68
64
  "webpack-hot-middleware": "^2.26.1",
69
65
  "webpackbar": "^7.0.0",
70
- "@nuxt/kit": "3.14.1592"
66
+ "@nuxt/kit": "3.15.1"
71
67
  },
72
68
  "devDependencies": {
73
- "@rspack/core": "1.1.2",
74
- "@types/hash-sum": "1.0.2",
75
- "@types/lodash-es": "4.17.12",
69
+ "@rspack/core": "1.1.8",
76
70
  "@types/pify": "5.0.4",
77
71
  "@types/webpack-bundle-analyzer": "4.7.0",
78
72
  "@types/webpack-hot-middleware": "2.25.9",
79
73
  "unbuild": "latest",
80
74
  "vue": "3.5.13",
81
- "@nuxt/schema": "3.14.1592"
75
+ "@nuxt/schema": "3.15.1"
82
76
  },
83
77
  "peerDependencies": {
84
78
  "vue": "^3.3.4"
85
79
  },
86
80
  "engines": {
87
- "node": "^14.18.0 || >=16.10.0"
81
+ "node": "^18.20.5 || ^20.9.0 || >=22.0.0"
88
82
  },
89
- "scripts": {}
83
+ "scripts": {
84
+ "test:attw": "attw --pack"
85
+ }
90
86
  }