@nuxt/webpack-builder 3.14.1592 → 3.15.0

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 +12 -286
  3. package/package.json +12 -14
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,17 +3,12 @@ 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';
@@ -22,6 +17,7 @@ import { env, nodeless } from 'unenv';
22
17
  import { cloneDeep } from 'lodash-es';
23
18
  import TimeFixPlugin from 'time-fix-plugin';
24
19
  import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin';
20
+ import escapeRegExp from 'escape-string-regexp';
25
21
  import { isTest } from 'std-env';
26
22
  import { EsbuildPlugin } from 'esbuild-loader';
27
23
  import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
@@ -30,246 +26,7 @@ import { createJiti } from 'jiti';
30
26
  import VueLoaderPlugin from 'vue-loader/dist/pluginWebpack5.js';
31
27
  import { mkdir, writeFile } from 'node:fs/promises';
32
28
  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
- }
29
+ import { hash } from 'ohash';
273
30
 
274
31
  const defaults = {
275
32
  globalPublicPath: "__webpack_public_path__",
@@ -297,16 +54,9 @@ ${options.globalPublicPath} = buildAssetsURL();
297
54
  };
298
55
  });
299
56
 
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
57
  const pluginName = "ChunkErrorPlugin";
307
58
  class ChunkErrorPlugin {
308
- constructor() {
309
- __publicField$3(this, "script", `
59
+ script = `
310
60
  if (typeof ${webpack.RuntimeGlobals.require} !== "undefined") {
311
61
  var _ensureChunk = ${webpack.RuntimeGlobals.ensureChunk};
312
62
  ${webpack.RuntimeGlobals.ensureChunk} = function (chunkId) {
@@ -317,8 +67,7 @@ if (typeof ${webpack.RuntimeGlobals.require} !== "undefined") {
317
67
  throw error
318
68
  });
319
69
  };
320
- };`);
321
- }
70
+ };`;
322
71
  apply(compiler) {
323
72
  compiler.hooks.thisCompilation.tap(
324
73
  pluginName,
@@ -418,15 +167,9 @@ function assets(ctx) {
418
167
  );
419
168
  }
420
169
 
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
170
  class WarningIgnorePlugin {
171
+ filter;
428
172
  constructor(filter) {
429
- __publicField$2(this, "filter");
430
173
  this.filter = filter;
431
174
  }
432
175
  apply(compiler) {
@@ -565,7 +308,7 @@ function baseTranspile(ctx) {
565
308
  }
566
309
  }
567
310
  if (typeof pattern === "string") {
568
- transpile.push(new RegExp(escapeRE(normalize(pattern))));
311
+ transpile.push(new RegExp(escapeRegExp(normalize(pattern))));
569
312
  } else if (pattern instanceof RegExp) {
570
313
  transpile.push(pattern);
571
314
  }
@@ -854,15 +597,9 @@ const isCSSRegExp = /\.css(?:\?[^.]+)?$/;
854
597
  const isCSS = (file) => isCSSRegExp.test(file);
855
598
  const isHotUpdate = (file) => file.includes("hot-update");
856
599
 
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
600
  class VueSSRClientPlugin {
601
+ options;
864
602
  constructor(options) {
865
- __publicField$1(this, "options");
866
603
  this.options = Object.assign({
867
604
  filename: null
868
605
  }, options);
@@ -896,7 +633,7 @@ class VueSSRClientPlugin {
896
633
  }
897
634
  if (isFileJS) {
898
635
  const componentHash = hash(chunkNames.join("|"));
899
- const map = assetsMapping[componentHash] || (assetsMapping[componentHash] = []);
636
+ const map = assetsMapping[componentHash] ||= [];
900
637
  map.push(file);
901
638
  }
902
639
  }
@@ -962,16 +699,10 @@ class VueSSRClientPlugin {
962
699
  }
963
700
  }
964
701
 
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
702
  const JS_MAP_RE = /\.js\.map$/;
972
703
  class VueSSRServerPlugin {
704
+ options;
973
705
  constructor(options = {}) {
974
- __publicField(this, "options");
975
706
  this.options = Object.assign({
976
707
  filename: null
977
708
  }, options);
@@ -1241,7 +972,7 @@ function serverStandalone(ctx) {
1241
972
  resolve(ctx.nuxt.options.rootDir, ctx.nuxt.options.dir.shared)
1242
973
  ];
1243
974
  if (!ctx.nuxt.options.dev) {
1244
- external.push("#internal/nuxt/paths");
975
+ external.push("#internal/nuxt/paths", "#app-manifest");
1245
976
  }
1246
977
  if (!Array.isArray(ctx.config.externals)) {
1247
978
  return;
@@ -1290,11 +1021,6 @@ const bundle = async (nuxt) => {
1290
1021
  if (config.name === "client" && nuxt.options.experimental.emitRouteChunkError && nuxt.options.builder !== "@nuxt/rspack-builder") {
1291
1022
  config.plugins.push(new ChunkErrorPlugin());
1292
1023
  }
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
1024
  }
1299
1025
  await nuxt.callHook(`${builder}:configResolved`, webpackConfigs);
1300
1026
  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.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -34,17 +34,14 @@
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",
40
+ "jiti": "^2.4.2",
43
41
  "lodash-es": "4.17.21",
44
- "magic-string": "^0.30.13",
45
- "memfs": "^4.14.0",
42
+ "magic-string": "^0.30.17",
43
+ "memfs": "^4.14.1",
46
44
  "mini-css-extract-plugin": "^2.9.2",
47
- "mlly": "^1.7.3",
48
45
  "ohash": "^1.1.4",
49
46
  "pathe": "^1.1.2",
50
47
  "pify": "^6.1.0",
@@ -58,7 +55,7 @@
58
55
  "time-fix-plugin": "^2.0.7",
59
56
  "ufo": "^1.5.4",
60
57
  "unenv": "^1.10.0",
61
- "unplugin": "^1.16.0",
58
+ "unplugin": "^2.1.0",
62
59
  "url-loader": "^4.1.1",
63
60
  "vue-bundle-renderer": "^2.1.1",
64
61
  "vue-loader": "^17.4.2",
@@ -67,24 +64,25 @@
67
64
  "webpack-dev-middleware": "^7.4.2",
68
65
  "webpack-hot-middleware": "^2.26.1",
69
66
  "webpackbar": "^7.0.0",
70
- "@nuxt/kit": "3.14.1592"
67
+ "@nuxt/kit": "3.15.0"
71
68
  },
72
69
  "devDependencies": {
73
- "@rspack/core": "1.1.2",
74
- "@types/hash-sum": "1.0.2",
70
+ "@rspack/core": "1.1.8",
75
71
  "@types/lodash-es": "4.17.12",
76
72
  "@types/pify": "5.0.4",
77
73
  "@types/webpack-bundle-analyzer": "4.7.0",
78
74
  "@types/webpack-hot-middleware": "2.25.9",
79
75
  "unbuild": "latest",
80
76
  "vue": "3.5.13",
81
- "@nuxt/schema": "3.14.1592"
77
+ "@nuxt/schema": "3.15.0"
82
78
  },
83
79
  "peerDependencies": {
84
80
  "vue": "^3.3.4"
85
81
  },
86
82
  "engines": {
87
- "node": "^14.18.0 || >=16.10.0"
83
+ "node": "^18.20.5 || ^20.9.0 || >=22.0.0"
88
84
  },
89
- "scripts": {}
85
+ "scripts": {
86
+ "test:attw": "attw --pack"
87
+ }
90
88
  }