@nuxt/webpack-builder 3.6.4 → 3.7.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.
@@ -0,0 +1,5 @@
1
+ import { NuxtBuilder } from '@nuxt/schema';
2
+
3
+ declare const bundle: NuxtBuilder['bundle'];
4
+
5
+ export { bundle };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Nuxt } from '@nuxt/schema';
1
+ import { NuxtBuilder } from '@nuxt/schema';
2
2
 
3
- declare function bundle(nuxt: Nuxt): Promise<unknown[] | undefined>;
3
+ declare const bundle: NuxtBuilder['bundle'];
4
4
 
5
5
  export { bundle };
package/dist/index.mjs CHANGED
@@ -3,6 +3,7 @@ import webpack from 'webpack';
3
3
  import { fromNodeMiddleware, defineEventHandler } from 'h3';
4
4
  import webpackDevMiddleware from 'webpack-dev-middleware';
5
5
  import webpackHotMiddleware from 'webpack-hot-middleware';
6
+ import { defu } from 'defu';
6
7
  import { parseURL, parseQuery, joinURL } from 'ufo';
7
8
  import { useNuxt, logger, requireModule } from '@nuxt/kit';
8
9
  import { pathToFileURL } from 'node:url';
@@ -40,6 +41,12 @@ function matchWithStringOrRegex(value, matcher) {
40
41
  return false;
41
42
  }
42
43
 
44
+ var __defProp$3 = Object.defineProperty;
45
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
46
+ var __publicField$3 = (obj, key, value) => {
47
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
48
+ return value;
49
+ };
43
50
  const stringTypes = ["Literal", "TemplateLiteral"];
44
51
  const NUXT_LIB_RE = /node_modules\/nuxt3?\//;
45
52
  const SUPPORTED_EXT_RE = /\.(m?[jt]sx?|vue)/;
@@ -162,8 +169,11 @@ const composableKeysPlugin = createUnplugin((options) => {
162
169
  });
163
170
  class ScopeTracker {
164
171
  constructor() {
172
+ // the top of the stack is not a part of current key, it is used for next level
173
+ __publicField$3(this, "scopeIndexStack");
174
+ __publicField$3(this, "curScopeKey");
165
175
  this.scopeIndexStack = [0];
166
- this.curScopeKey = "0";
176
+ this.curScopeKey = "";
167
177
  }
168
178
  getKey() {
169
179
  return this.scopeIndexStack.slice(0, -1).join("-");
@@ -180,8 +190,10 @@ class ScopeTracker {
180
190
  }
181
191
  class ScopedVarsCollector {
182
192
  constructor() {
193
+ __publicField$3(this, "curScopeKey");
194
+ __publicField$3(this, "all");
183
195
  this.all = /* @__PURE__ */ new Map();
184
- this.curScopeKey = "0";
196
+ this.curScopeKey = "";
185
197
  }
186
198
  refresh(scopeKey) {
187
199
  this.curScopeKey = scopeKey;
@@ -196,7 +208,7 @@ class ScopedVarsCollector {
196
208
  }
197
209
  hasVar(scopeKey, name) {
198
210
  const indices = scopeKey.split("-").map(Number);
199
- for (let i = indices.length; i > 0; i--) {
211
+ for (let i = indices.length; i >= 0; i--) {
200
212
  if (this.all.get(indices.slice(0, i).join("-"))?.has(name)) {
201
213
  return true;
202
214
  }
@@ -335,6 +347,7 @@ function createWebpackConfigContext(nuxt) {
335
347
  return {
336
348
  nuxt,
337
349
  options: nuxt.options,
350
+ userConfig: nuxt.options.webpack,
338
351
  config: {},
339
352
  name: "base",
340
353
  isDev: nuxt.options.dev,
@@ -357,12 +370,11 @@ function applyPresets(ctx, presets) {
357
370
  }
358
371
  }
359
372
  function fileName(ctx, key) {
360
- const { options } = ctx;
361
- let fileName2 = options.webpack.filenames[key];
373
+ let fileName2 = ctx.userConfig.filenames[key];
362
374
  if (typeof fileName2 === "function") {
363
375
  fileName2 = fileName2(ctx);
364
376
  }
365
- if (typeof fileName2 === "string" && options.dev) {
377
+ if (typeof fileName2 === "string" && ctx.options.dev) {
366
378
  const hash = /\[(chunkhash|contenthash|hash)(?::(\d+))?]/.exec(fileName2);
367
379
  if (hash) {
368
380
  logger.warn(`Notice: Please do not use ${hash[1]} in dev mode to prevent memory leak`);
@@ -371,22 +383,6 @@ function fileName(ctx, key) {
371
383
  return fileName2;
372
384
  }
373
385
  function getWebpackConfig(ctx) {
374
- const { extend } = ctx.options.build;
375
- if (typeof extend === "function") {
376
- logger.warn("[nuxt] The `build.extend` and `webpack.build.extend` properties have been deprecated in Nuxt 3 for some time and will be removed in a future minor release. Instead, you can extend webpack config using the `webpack:config` hook.");
377
- const extendedConfig = extend.call(
378
- {},
379
- ctx.config,
380
- { loaders: [], ...ctx }
381
- ) || ctx.config;
382
- const pragma = /@|#/;
383
- const { devtool } = extendedConfig;
384
- if (typeof devtool === "string" && pragma.test(devtool)) {
385
- extendedConfig.devtool = devtool.replace(pragma, "");
386
- logger.warn(`devtool has been normalized to ${extendedConfig.devtool} as webpack documented value`);
387
- }
388
- return extendedConfig;
389
- }
390
386
  return cloneDeep(ctx.config);
391
387
  }
392
388
 
@@ -397,7 +393,7 @@ function assets(ctx) {
397
393
  use: [{
398
394
  loader: "url-loader",
399
395
  options: {
400
- ...ctx.options.webpack.loaders.imgUrl,
396
+ ...ctx.userConfig.loaders.imgUrl,
401
397
  name: fileName(ctx, "img")
402
398
  }
403
399
  }]
@@ -407,7 +403,7 @@ function assets(ctx) {
407
403
  use: [{
408
404
  loader: "url-loader",
409
405
  options: {
410
- ...ctx.options.webpack.loaders.fontUrl,
406
+ ...ctx.userConfig.loaders.fontUrl,
411
407
  name: fileName(ctx, "font")
412
408
  }
413
409
  }]
@@ -417,7 +413,7 @@ function assets(ctx) {
417
413
  use: [{
418
414
  loader: "file-loader",
419
415
  options: {
420
- ...ctx.options.webpack.loaders.file,
416
+ ...ctx.userConfig.loaders.file,
421
417
  name: fileName(ctx, "video")
422
418
  }
423
419
  }]
@@ -425,8 +421,15 @@ function assets(ctx) {
425
421
  );
426
422
  }
427
423
 
424
+ var __defProp$2 = Object.defineProperty;
425
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
426
+ var __publicField$2 = (obj, key, value) => {
427
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
428
+ return value;
429
+ };
428
430
  class WarningIgnorePlugin {
429
431
  constructor(filter) {
432
+ __publicField$2(this, "filter");
430
433
  this.filter = filter;
431
434
  }
432
435
  apply(compiler) {
@@ -446,19 +449,18 @@ function base(ctx) {
446
449
  ]);
447
450
  }
448
451
  function baseConfig(ctx) {
449
- const { options } = ctx;
450
452
  ctx.config = {
451
453
  name: ctx.name,
452
- entry: { app: [resolve(options.appDir, options.experimental.asyncEntry ? "entry.async" : "entry")] },
454
+ entry: { app: [resolve(ctx.options.appDir, ctx.options.experimental.asyncEntry ? "entry.async" : "entry")] },
453
455
  module: { rules: [] },
454
456
  plugins: [],
455
457
  externals: [],
456
458
  optimization: {
457
- ...options.webpack.optimization,
459
+ ...ctx.userConfig.optimization,
458
460
  minimizer: []
459
461
  },
460
462
  experiments: {
461
- ...options.webpack.experiments
463
+ ...ctx.userConfig.experiments
462
464
  },
463
465
  mode: ctx.isDev ? "development" : "production",
464
466
  cache: getCache(ctx),
@@ -468,16 +470,15 @@ function baseConfig(ctx) {
468
470
  };
469
471
  }
470
472
  function basePlugins(ctx) {
471
- const { config, options, nuxt } = ctx;
472
- config.plugins = config.plugins || [];
473
- if (options.dev) {
474
- config.plugins.push(new TimeFixPlugin());
473
+ ctx.config.plugins = ctx.config.plugins || [];
474
+ if (ctx.options.dev) {
475
+ ctx.config.plugins.push(new TimeFixPlugin());
475
476
  }
476
- config.plugins.push(...options.webpack.plugins || []);
477
- config.plugins.push(new WarningIgnorePlugin(getWarningIgnoreFilter(ctx)));
478
- config.plugins.push(new webpack.DefinePlugin(getEnv(ctx)));
479
- if (ctx.isServer || ctx.isDev && options.webpack.friendlyErrors) {
480
- config.plugins.push(
477
+ ctx.config.plugins.push(...ctx.userConfig.plugins || []);
478
+ ctx.config.plugins.push(new WarningIgnorePlugin(getWarningIgnoreFilter(ctx)));
479
+ ctx.config.plugins.push(new webpack.DefinePlugin(getEnv(ctx)));
480
+ if (ctx.isServer || ctx.isDev && ctx.userConfig.friendlyErrors) {
481
+ ctx.config.plugins.push(
481
482
  new FriendlyErrorsWebpackPlugin({
482
483
  clearConsole: false,
483
484
  reporter: "consola",
@@ -486,13 +487,13 @@ function basePlugins(ctx) {
486
487
  })
487
488
  );
488
489
  }
489
- if (nuxt.options.webpack.profile) {
490
+ if (ctx.nuxt.options.webpack.profile) {
490
491
  const colors = {
491
492
  client: "green",
492
493
  server: "orange",
493
494
  modern: "blue"
494
495
  };
495
- config.plugins.push(new WebpackBar({
496
+ ctx.config.plugins.push(new WebpackBar({
496
497
  name: ctx.name,
497
498
  color: colors[ctx.name],
498
499
  reporters: ["stats"],
@@ -502,21 +503,21 @@ function basePlugins(ctx) {
502
503
  reporter: {
503
504
  change: (_, { shortPath }) => {
504
505
  if (!ctx.isServer) {
505
- nuxt.callHook("webpack:change", shortPath);
506
+ ctx.nuxt.callHook("webpack:change", shortPath);
506
507
  }
507
508
  },
508
509
  done: ({ state }) => {
509
510
  if (state.hasErrors) {
510
- nuxt.callHook("webpack:error");
511
+ ctx.nuxt.callHook("webpack:error");
511
512
  } else {
512
513
  logger.success(`${state.name} ${state.message}`);
513
514
  }
514
515
  },
515
516
  allDone: () => {
516
- nuxt.callHook("webpack:done");
517
+ ctx.nuxt.callHook("webpack:done");
517
518
  },
518
519
  progress({ statesArray }) {
519
- nuxt.callHook("webpack:progress", statesArray);
520
+ ctx.nuxt.callHook("webpack:progress", statesArray);
520
521
  }
521
522
  }
522
523
  }
@@ -524,12 +525,11 @@ function basePlugins(ctx) {
524
525
  }
525
526
  }
526
527
  function baseAlias(ctx) {
527
- const { options } = ctx;
528
528
  ctx.alias = {
529
- "#app": options.appDir,
530
- "#build/plugins": resolve(options.buildDir, "plugins", ctx.isClient ? "client" : "server"),
531
- "#build": options.buildDir,
532
- ...options.alias,
529
+ "#app": ctx.options.appDir,
530
+ "#build/plugins": resolve(ctx.options.buildDir, "plugins", ctx.isClient ? "client" : "server"),
531
+ "#build": ctx.options.buildDir,
532
+ ...ctx.options.alias,
533
533
  ...ctx.alias
534
534
  };
535
535
  if (ctx.isClient) {
@@ -537,22 +537,20 @@ function baseAlias(ctx) {
537
537
  }
538
538
  }
539
539
  function baseResolve(ctx) {
540
- const { options, config } = ctx;
541
- const webpackModulesDir = ["node_modules"].concat(options.modulesDir);
542
- config.resolve = {
540
+ const webpackModulesDir = ["node_modules"].concat(ctx.options.modulesDir);
541
+ ctx.config.resolve = {
543
542
  extensions: [".wasm", ".mjs", ".js", ".ts", ".json", ".vue", ".jsx", ".tsx"],
544
543
  alias: ctx.alias,
545
544
  modules: webpackModulesDir,
546
545
  fullySpecified: false,
547
- ...config.resolve
546
+ ...ctx.config.resolve
548
547
  };
549
- config.resolveLoader = {
548
+ ctx.config.resolveLoader = {
550
549
  modules: webpackModulesDir,
551
- ...config.resolveLoader
550
+ ...ctx.config.resolveLoader
552
551
  };
553
552
  }
554
553
  function baseTranspile(ctx) {
555
- const { options } = ctx;
556
554
  const transpile = [
557
555
  /\.vue\.js/i,
558
556
  // include SFCs in node_modules
@@ -560,7 +558,7 @@ function baseTranspile(ctx) {
560
558
  /vue-demi/,
561
559
  /(^|\/)nuxt\/(dist\/)?(app|[^/]+\/runtime)($|\/)/
562
560
  ];
563
- for (let pattern of options.build.transpile) {
561
+ for (let pattern of ctx.options.build.transpile) {
564
562
  if (typeof pattern === "function") {
565
563
  const result = pattern(ctx);
566
564
  if (result) {
@@ -576,43 +574,44 @@ function baseTranspile(ctx) {
576
574
  ctx.transpile = [...transpile, ...ctx.transpile];
577
575
  }
578
576
  function getCache(ctx) {
579
- const { options } = ctx;
580
- if (!options.dev) {
577
+ if (!ctx.options.dev) {
581
578
  return false;
582
579
  }
583
580
  }
584
581
  function getOutput(ctx) {
585
- const { options } = ctx;
586
582
  return {
587
- path: resolve(options.buildDir, "dist", ctx.isServer ? "server" : joinURL("client", options.app.buildAssetsDir)),
583
+ path: resolve(ctx.options.buildDir, "dist", ctx.isServer ? "server" : joinURL("client", ctx.options.app.buildAssetsDir)),
588
584
  filename: fileName(ctx, "app"),
589
585
  chunkFilename: fileName(ctx, "chunk"),
590
- publicPath: joinURL(options.app.baseURL, options.app.buildAssetsDir)
586
+ publicPath: joinURL(ctx.options.app.baseURL, ctx.options.app.buildAssetsDir)
591
587
  };
592
588
  }
593
589
  function getWarningIgnoreFilter(ctx) {
594
- const { options } = ctx;
595
590
  const filters = [
596
591
  // Hide warnings about plugins without a default export (#1179)
597
592
  (warn) => warn.name === "ModuleDependencyWarning" && warn.message.includes("export 'default'") && warn.message.includes("nuxt_plugin_"),
598
- ...options.webpack.warningIgnoreFilters || []
593
+ ...ctx.userConfig.warningIgnoreFilters || []
599
594
  ];
600
595
  return (warn) => !filters.some((ignoreFilter) => ignoreFilter(warn));
601
596
  }
602
597
  function getEnv(ctx) {
603
- const { options } = ctx;
604
598
  const _env = {
605
599
  "process.env.NODE_ENV": JSON.stringify(ctx.config.mode),
606
- "process.mode": JSON.stringify(ctx.config.mode),
607
- "process.dev": options.dev,
608
- "process.test": isTest,
609
600
  __NUXT_VERSION__: JSON.stringify(ctx.nuxt._version),
610
601
  "process.env.VUE_ENV": JSON.stringify(ctx.name),
602
+ "process.env.NUXT_ASYNC_CONTEXT": ctx.options.experimental.asyncContext,
603
+ "process.dev": ctx.options.dev,
604
+ "process.test": isTest,
611
605
  "process.browser": ctx.isClient,
612
606
  "process.client": ctx.isClient,
613
- "process.server": ctx.isServer
607
+ "process.server": ctx.isServer,
608
+ "import.meta.dev": ctx.options.dev,
609
+ "import.meta.test": isTest,
610
+ "import.meta.browser": ctx.isClient,
611
+ "import.meta.client": ctx.isClient,
612
+ "import.meta.server": ctx.isServer
614
613
  };
615
- if (options.webpack.aggressiveCodeRemoval) {
614
+ if (ctx.userConfig.aggressiveCodeRemoval) {
616
615
  _env["typeof process"] = JSON.stringify(ctx.isServer ? "object" : "undefined");
617
616
  _env["typeof window"] = _env["typeof document"] = JSON.stringify(!ctx.isServer ? "object" : "undefined");
618
617
  }
@@ -625,10 +624,9 @@ const statsMap = {
625
624
  };
626
625
 
627
626
  function esbuild(ctx) {
628
- const { config } = ctx;
629
- const target = ctx.isServer ? "es2019" : "chrome85";
630
- config.optimization.minimizer.push(new EsbuildPlugin());
631
- config.module.rules.push(
627
+ const target = ctx.isServer ? "es2020" : "chrome85";
628
+ ctx.config.optimization.minimizer.push(new EsbuildPlugin());
629
+ ctx.config.module.rules.push(
632
630
  {
633
631
  test: /\.m?[jt]s$/i,
634
632
  loader: "esbuild-loader",
@@ -668,7 +666,7 @@ function pug(ctx) {
668
666
  resourceQuery: /^\?vue/i,
669
667
  use: [{
670
668
  loader: "pug-plain-loader",
671
- options: ctx.options.webpack.loaders.pugPlain
669
+ options: ctx.userConfig.loaders.pugPlain
672
670
  }]
673
671
  },
674
672
  {
@@ -676,7 +674,7 @@ function pug(ctx) {
676
674
  "raw-loader",
677
675
  {
678
676
  loader: "pug-plain-loader",
679
- options: ctx.options.webpack.loaders.pugPlain
677
+ options: ctx.userConfig.loaders.pugPlain
680
678
  }
681
679
  ]
682
680
  }
@@ -761,45 +759,41 @@ function style(ctx) {
761
759
  ]);
762
760
  }
763
761
  function minimizer(ctx) {
764
- const { options, config } = ctx;
765
- if (options.webpack.optimizeCSS && Array.isArray(config.optimization.minimizer)) {
766
- config.optimization.minimizer.push(new CssMinimizerPlugin({
767
- ...options.webpack.optimizeCSS
762
+ if (ctx.userConfig.optimizeCSS && Array.isArray(ctx.config.optimization.minimizer)) {
763
+ ctx.config.optimization.minimizer.push(new CssMinimizerPlugin({
764
+ ...ctx.userConfig.optimizeCSS
768
765
  }));
769
766
  }
770
767
  }
771
768
  function extractCSS(ctx) {
772
- const { options, config } = ctx;
773
- if (options.webpack.extractCSS) {
774
- config.plugins.push(new MiniCssExtractPlugin({
769
+ if (ctx.userConfig.extractCSS) {
770
+ ctx.config.plugins.push(new MiniCssExtractPlugin({
775
771
  filename: fileName(ctx, "css"),
776
772
  chunkFilename: fileName(ctx, "css"),
777
- ...options.webpack.extractCSS === true ? {} : options.webpack.extractCSS
773
+ ...ctx.userConfig.extractCSS === true ? {} : ctx.userConfig.extractCSS
778
774
  }));
779
775
  }
780
776
  }
781
777
  function loaders(ctx) {
782
- const { config, options } = ctx;
783
- config.module.rules.push(createdStyleRule("css", /\.css$/i, null, ctx));
784
- config.module.rules.push(createdStyleRule("postcss", /\.p(ost)?css$/i, null, ctx));
785
- const lessLoader = { loader: "less-loader", options: options.webpack.loaders.less };
786
- config.module.rules.push(createdStyleRule("less", /\.less$/i, lessLoader, ctx));
787
- const sassLoader = { loader: "sass-loader", options: options.webpack.loaders.sass };
788
- config.module.rules.push(createdStyleRule("sass", /\.sass$/i, sassLoader, ctx));
789
- const scssLoader = { loader: "sass-loader", options: options.webpack.loaders.scss };
790
- config.module.rules.push(createdStyleRule("scss", /\.scss$/i, scssLoader, ctx));
791
- const stylusLoader = { loader: "stylus-loader", options: options.webpack.loaders.stylus };
792
- config.module.rules.push(createdStyleRule("stylus", /\.styl(us)?$/i, stylusLoader, ctx));
778
+ ctx.config.module.rules.push(createdStyleRule("css", /\.css$/i, null, ctx));
779
+ ctx.config.module.rules.push(createdStyleRule("postcss", /\.p(ost)?css$/i, null, ctx));
780
+ const lessLoader = { loader: "less-loader", options: ctx.userConfig.loaders.less };
781
+ ctx.config.module.rules.push(createdStyleRule("less", /\.less$/i, lessLoader, ctx));
782
+ const sassLoader = { loader: "sass-loader", options: ctx.userConfig.loaders.sass };
783
+ ctx.config.module.rules.push(createdStyleRule("sass", /\.sass$/i, sassLoader, ctx));
784
+ const scssLoader = { loader: "sass-loader", options: ctx.userConfig.loaders.scss };
785
+ ctx.config.module.rules.push(createdStyleRule("scss", /\.scss$/i, scssLoader, ctx));
786
+ const stylusLoader = { loader: "stylus-loader", options: ctx.userConfig.loaders.stylus };
787
+ ctx.config.module.rules.push(createdStyleRule("stylus", /\.styl(us)?$/i, stylusLoader, ctx));
793
788
  }
794
789
  function createdStyleRule(lang, test, processorLoader, ctx) {
795
- const { options } = ctx;
796
790
  const styleLoaders = [
797
791
  createPostcssLoadersRule(ctx),
798
792
  processorLoader
799
793
  ].filter(Boolean);
800
- options.webpack.loaders.css.importLoaders = options.webpack.loaders.cssModules.importLoaders = styleLoaders.length;
801
- const cssLoaders = createCssLoadersRule(ctx, options.webpack.loaders.css);
802
- const cssModuleLoaders = createCssLoadersRule(ctx, options.webpack.loaders.cssModules);
794
+ ctx.userConfig.loaders.css.importLoaders = ctx.userConfig.loaders.cssModules.importLoaders = styleLoaders.length;
795
+ const cssLoaders = createCssLoadersRule(ctx, ctx.userConfig.loaders.css);
796
+ const cssModuleLoaders = createCssLoadersRule(ctx, ctx.userConfig.loaders.cssModules);
803
797
  return {
804
798
  test,
805
799
  oneOf: [
@@ -816,9 +810,8 @@ function createdStyleRule(lang, test, processorLoader, ctx) {
816
810
  };
817
811
  }
818
812
  function createCssLoadersRule(ctx, cssLoaderOptions) {
819
- const { options } = ctx;
820
813
  const cssLoader = { loader: "css-loader", options: cssLoaderOptions };
821
- if (options.webpack.extractCSS) {
814
+ if (ctx.userConfig.extractCSS) {
822
815
  if (ctx.isServer) {
823
816
  if (cssLoader.options.modules) {
824
817
  cssLoader.options.modules.exportOnlyLocals = cssLoader.options.modules.exportOnlyLocals ?? true;
@@ -842,11 +835,10 @@ function createCssLoadersRule(ctx, cssLoaderOptions) {
842
835
  ];
843
836
  }
844
837
  function createPostcssLoadersRule(ctx) {
845
- const { options, nuxt } = ctx;
846
- if (!options.postcss) {
838
+ if (!ctx.options.postcss) {
847
839
  return;
848
840
  }
849
- const config = getPostcssConfig(nuxt);
841
+ const config = getPostcssConfig(ctx.nuxt);
850
842
  if (!config) {
851
843
  return;
852
844
  }
@@ -872,8 +864,15 @@ const extractQueryPartJS = (file) => isJSRegExp.exec(file)?.[1];
872
864
  const isCSS = (file) => /\.css(\?[^.]+)?$/.test(file);
873
865
  const isHotUpdate = (file) => file.includes("hot-update");
874
866
 
867
+ var __defProp$1 = Object.defineProperty;
868
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
869
+ var __publicField$1 = (obj, key, value) => {
870
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
871
+ return value;
872
+ };
875
873
  class VueSSRClientPlugin {
876
874
  constructor(options) {
875
+ __publicField$1(this, "options");
877
876
  this.options = Object.assign({
878
877
  filename: null
879
878
  }, options);
@@ -952,9 +951,16 @@ class VueSSRClientPlugin {
952
951
  }
953
952
  }
954
953
 
954
+ var __defProp = Object.defineProperty;
955
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
956
+ var __publicField = (obj, key, value) => {
957
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
958
+ return value;
959
+ };
955
960
  const JS_MAP_RE = /\.js\.map$/;
956
961
  class VueSSRServerPlugin {
957
962
  constructor(options = {}) {
963
+ __publicField(this, "options");
958
964
  this.options = Object.assign({
959
965
  filename: null
960
966
  }, options);
@@ -1021,27 +1027,26 @@ class VueSSRServerPlugin {
1021
1027
  }
1022
1028
 
1023
1029
  function vue(ctx) {
1024
- const { options, config } = ctx;
1025
- config.plugins.push(new (VueLoaderPlugin.default || VueLoaderPlugin)());
1026
- config.module.rules.push({
1030
+ ctx.config.plugins.push(new (VueLoaderPlugin.default || VueLoaderPlugin)());
1031
+ ctx.config.module.rules.push({
1027
1032
  test: /\.vue$/i,
1028
1033
  loader: "vue-loader",
1029
1034
  options: {
1030
1035
  reactivityTransform: ctx.nuxt.options.experimental.reactivityTransform,
1031
- ...options.webpack.loaders.vue
1036
+ ...ctx.userConfig.loaders.vue
1032
1037
  }
1033
1038
  });
1034
1039
  if (ctx.isClient) {
1035
- config.plugins.push(new VueSSRClientPlugin({
1036
- filename: resolve(options.buildDir, "dist/server", `${ctx.name}.manifest.json`),
1040
+ ctx.config.plugins.push(new VueSSRClientPlugin({
1041
+ filename: resolve(ctx.options.buildDir, "dist/server", `${ctx.name}.manifest.json`),
1037
1042
  nuxt: ctx.nuxt
1038
1043
  }));
1039
1044
  } else {
1040
- config.plugins.push(new VueSSRServerPlugin({
1045
+ ctx.config.plugins.push(new VueSSRServerPlugin({
1041
1046
  filename: `${ctx.name}.manifest.json`
1042
1047
  }));
1043
1048
  }
1044
- config.plugins.push(new webpack.DefinePlugin({
1049
+ ctx.config.plugins.push(new webpack.DefinePlugin({
1045
1050
  __VUE_OPTIONS_API__: "true",
1046
1051
  __VUE_PROD_DEVTOOLS__: "false"
1047
1052
  }));
@@ -1075,11 +1080,12 @@ function clientDevtool(ctx) {
1075
1080
  ctx.config.devtool = false;
1076
1081
  return;
1077
1082
  }
1083
+ const prefix = ctx.nuxt.options.sourcemap.client === "hidden" ? "hidden-" : "";
1078
1084
  if (!ctx.isDev) {
1079
- ctx.config.devtool = "source-map";
1085
+ ctx.config.devtool = prefix + "source-map";
1080
1086
  return;
1081
1087
  }
1082
- ctx.config.devtool = "eval-cheap-module-source-map";
1088
+ ctx.config.devtool = prefix + "eval-cheap-module-source-map";
1083
1089
  }
1084
1090
  function clientPerformance(ctx) {
1085
1091
  ctx.config.performance = {
@@ -1089,48 +1095,46 @@ function clientPerformance(ctx) {
1089
1095
  };
1090
1096
  }
1091
1097
  function clientHMR(ctx) {
1092
- const { options, config } = ctx;
1093
1098
  if (!ctx.isDev) {
1094
1099
  return;
1095
1100
  }
1096
- const clientOptions = options.webpack.hotMiddleware?.client || {};
1101
+ const clientOptions = ctx.userConfig.hotMiddleware?.client || {};
1097
1102
  const hotMiddlewareClientOptions = {
1098
1103
  reload: true,
1099
1104
  timeout: 3e4,
1100
- path: joinURL(options.app.baseURL, "__webpack_hmr", ctx.name),
1105
+ path: joinURL(ctx.options.app.baseURL, "__webpack_hmr", ctx.name),
1101
1106
  ...clientOptions,
1102
1107
  ansiColors: JSON.stringify(clientOptions.ansiColors || {}),
1103
1108
  overlayStyles: JSON.stringify(clientOptions.overlayStyles || {}),
1104
1109
  name: ctx.name
1105
1110
  };
1106
1111
  const hotMiddlewareClientOptionsStr = querystring.stringify(hotMiddlewareClientOptions);
1107
- const app = config.entry.app;
1112
+ const app = ctx.config.entry.app;
1108
1113
  app.unshift(
1109
1114
  // https://github.com/glenjamin/webpack-hot-middleware#config
1110
1115
  `webpack-hot-middleware/client?${hotMiddlewareClientOptionsStr}`
1111
1116
  );
1112
- config.plugins = config.plugins || [];
1113
- config.plugins.push(new webpack.HotModuleReplacementPlugin());
1117
+ ctx.config.plugins = ctx.config.plugins || [];
1118
+ ctx.config.plugins.push(new webpack.HotModuleReplacementPlugin());
1114
1119
  }
1115
1120
  function clientOptimization(_ctx) {
1116
1121
  }
1117
1122
  function clientPlugins(ctx) {
1118
- const { options, config } = ctx;
1119
- if (!ctx.isDev && ctx.name === "client" && options.webpack.analyze) {
1120
- const statsDir = resolve(options.analyzeDir);
1121
- config.plugins.push(new BundleAnalyzerPlugin({
1123
+ if (!ctx.isDev && ctx.name === "client" && ctx.userConfig.analyze) {
1124
+ const statsDir = resolve(ctx.options.analyzeDir);
1125
+ ctx.config.plugins.push(new BundleAnalyzerPlugin({
1122
1126
  analyzerMode: "static",
1123
1127
  defaultSizes: "gzip",
1124
1128
  generateStatsFile: true,
1125
1129
  openAnalyzer: true,
1126
1130
  reportFilename: resolve(statsDir, `${ctx.name}.html`),
1127
1131
  statsFilename: resolve(statsDir, `${ctx.name}.json`),
1128
- ...options.webpack.analyze === true ? {} : options.webpack.analyze
1132
+ ...ctx.userConfig.analyze === true ? {} : ctx.userConfig.analyze
1129
1133
  }));
1130
1134
  }
1131
1135
  if (!ctx.nuxt.options.ssr) {
1132
1136
  if (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev) {
1133
- config.plugins.push(new ForkTSCheckerWebpackPlugin({
1137
+ ctx.config.plugins.push(new ForkTSCheckerWebpackPlugin({
1134
1138
  logger
1135
1139
  }));
1136
1140
  }
@@ -1138,12 +1142,11 @@ function clientPlugins(ctx) {
1138
1142
  }
1139
1143
 
1140
1144
  function node(ctx) {
1141
- const { config } = ctx;
1142
- config.target = "node";
1143
- config.node = false;
1144
- config.experiments.outputModule = true;
1145
- config.output = {
1146
- ...config.output,
1145
+ ctx.config.target = "node";
1146
+ ctx.config.node = false;
1147
+ ctx.config.experiments.outputModule = true;
1148
+ ctx.config.output = {
1149
+ ...ctx.config.output,
1147
1150
  chunkFilename: "[name].mjs",
1148
1151
  chunkFormat: "module",
1149
1152
  chunkLoading: "import",
@@ -1161,8 +1164,8 @@ function node(ctx) {
1161
1164
  type: "module"
1162
1165
  }
1163
1166
  };
1164
- config.performance = {
1165
- ...config.performance,
1167
+ ctx.config.performance = {
1168
+ ...ctx.config.performance,
1166
1169
  hints: false,
1167
1170
  maxEntrypointSize: Infinity,
1168
1171
  maxAssetSize: Infinity
@@ -1183,10 +1186,14 @@ function server(ctx) {
1183
1186
  return getWebpackConfig(ctx);
1184
1187
  }
1185
1188
  function serverPreset(ctx) {
1186
- const { config } = ctx;
1187
- config.output.filename = "server.mjs";
1188
- config.devtool = ctx.nuxt.options.sourcemap.server ? ctx.isDev ? "cheap-module-source-map" : "source-map" : false;
1189
- config.optimization = {
1189
+ ctx.config.output.filename = "server.mjs";
1190
+ if (ctx.nuxt.options.sourcemap.server) {
1191
+ const prefix = ctx.nuxt.options.sourcemap.server === "hidden" ? "hidden-" : "";
1192
+ ctx.config.devtool = prefix + ctx.isDev ? "cheap-module-source-map" : "source-map";
1193
+ } else {
1194
+ ctx.config.devtool = false;
1195
+ }
1196
+ ctx.config.optimization = {
1190
1197
  splitChunks: false,
1191
1198
  minimize: false
1192
1199
  };
@@ -1222,25 +1229,25 @@ function serverStandalone(ctx) {
1222
1229
  });
1223
1230
  }
1224
1231
  function serverPlugins(ctx) {
1225
- const { config, options } = ctx;
1226
- config.plugins = config.plugins || [];
1227
- if (options.webpack.serverURLPolyfill) {
1228
- config.plugins.push(new webpack.ProvidePlugin({
1229
- URL: [options.webpack.serverURLPolyfill, "URL"],
1230
- URLSearchParams: [options.webpack.serverURLPolyfill, "URLSearchParams"]
1232
+ ctx.config.plugins = ctx.config.plugins || [];
1233
+ if (ctx.userConfig.serverURLPolyfill) {
1234
+ ctx.config.plugins.push(new webpack.ProvidePlugin({
1235
+ URL: [ctx.userConfig.serverURLPolyfill, "URL"],
1236
+ URLSearchParams: [ctx.userConfig.serverURLPolyfill, "URLSearchParams"]
1231
1237
  }));
1232
1238
  }
1233
1239
  if (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev) {
1234
- config.plugins.push(new ForkTSCheckerWebpackPlugin({
1240
+ ctx.config.plugins.push(new ForkTSCheckerWebpackPlugin({
1235
1241
  logger
1236
1242
  }));
1237
1243
  }
1238
1244
  }
1239
1245
 
1240
- async function bundle(nuxt) {
1246
+ const bundle = async (nuxt) => {
1241
1247
  registerVirtualModules();
1242
1248
  const webpackConfigs = [client, ...nuxt.options.ssr ? [server] : []].map((preset) => {
1243
1249
  const ctx = createWebpackConfigContext(nuxt);
1250
+ ctx.userConfig = defu(nuxt.options.webpack[`$${preset.name}`], ctx.userConfig);
1244
1251
  applyPresets(ctx, preset);
1245
1252
  return getWebpackConfig(ctx);
1246
1253
  });
@@ -1248,13 +1255,13 @@ async function bundle(nuxt) {
1248
1255
  const mfs = nuxt.options.dev ? createMFS() : null;
1249
1256
  for (const config of webpackConfigs) {
1250
1257
  config.plugins.push(DynamicBasePlugin.webpack({
1251
- sourcemap: nuxt.options.sourcemap[config.name]
1258
+ sourcemap: !!nuxt.options.sourcemap[config.name]
1252
1259
  }));
1253
1260
  if (config.name === "client" && nuxt.options.experimental.emitRouteChunkError) {
1254
1261
  config.plugins.push(new ChunkErrorPlugin());
1255
1262
  }
1256
1263
  config.plugins.push(composableKeysPlugin.webpack({
1257
- sourcemap: nuxt.options.sourcemap[config.name],
1264
+ sourcemap: !!nuxt.options.sourcemap[config.name],
1258
1265
  rootDir: nuxt.options.rootDir,
1259
1266
  composables: nuxt.options.optimization.keyedComposables
1260
1267
  }));
@@ -1273,12 +1280,13 @@ async function bundle(nuxt) {
1273
1280
  }
1274
1281
  });
1275
1282
  if (nuxt.options.dev) {
1276
- return Promise.all(compilers.map((c) => compile(c)));
1283
+ await Promise.all(compilers.map((c) => compile(c)));
1284
+ return;
1277
1285
  }
1278
1286
  for (const c of compilers) {
1279
1287
  await compile(c);
1280
1288
  }
1281
- }
1289
+ };
1282
1290
  async function createDevMiddleware(compiler) {
1283
1291
  const nuxt = useNuxt();
1284
1292
  logger.debug("Creating webpack middleware...");
@@ -1306,17 +1314,16 @@ async function createDevMiddleware(compiler) {
1306
1314
  }
1307
1315
  async function compile(compiler) {
1308
1316
  const nuxt = useNuxt();
1309
- const { name } = compiler.options;
1310
- await nuxt.callHook("webpack:compile", { name, compiler });
1317
+ await nuxt.callHook("webpack:compile", { name: compiler.options.name, compiler });
1311
1318
  compiler.hooks.done.tap("load-resources", async (stats2) => {
1312
- await nuxt.callHook("webpack:compiled", { name, compiler, stats: stats2 });
1319
+ await nuxt.callHook("webpack:compiled", { name: compiler.options.name, compiler, stats: stats2 });
1313
1320
  });
1314
1321
  if (nuxt.options.dev) {
1315
1322
  const compilersWatching = [];
1316
1323
  nuxt.hook("close", async () => {
1317
1324
  await Promise.all(compilersWatching.map((watching) => pify(watching.close.bind(watching))()));
1318
1325
  });
1319
- if (name === "client") {
1326
+ if (compiler.options.name === "client") {
1320
1327
  return new Promise((resolve, reject) => {
1321
1328
  compiler.hooks.done.tap("nuxt-dev", () => {
1322
1329
  resolve(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/webpack-builder",
3
- "version": "3.6.4",
3
+ "version": "3.7.0",
4
4
  "repository": "nuxt/nuxt",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,57 +17,58 @@
17
17
  ],
18
18
  "dependencies": {
19
19
  "@nuxt/friendly-errors-webpack-plugin": "^2.5.2",
20
- "autoprefixer": "^10.4.14",
20
+ "autoprefixer": "^10.4.15",
21
21
  "css-loader": "^6.8.1",
22
22
  "css-minimizer-webpack-plugin": "^5.0.1",
23
23
  "cssnano": "^6.0.1",
24
- "esbuild-loader": "^3.0.1",
24
+ "defu": "^6.1.2",
25
+ "esbuild-loader": "^4.0.1",
25
26
  "escape-string-regexp": "^5.0.0",
26
27
  "estree-walker": "^3.0.3",
27
28
  "file-loader": "^6.2.0",
28
29
  "fork-ts-checker-webpack-plugin": "^8.0.0",
29
30
  "fs-extra": "^11.1.1",
30
- "h3": "^1.7.1",
31
+ "h3": "^1.8.0",
31
32
  "hash-sum": "^2.0.0",
32
33
  "lodash-es": "^4.17.21",
33
- "magic-string": "^0.30.1",
34
- "memfs": "^4.2.0",
34
+ "magic-string": "^0.30.3",
35
+ "memfs": "^4.2.1",
35
36
  "mini-css-extract-plugin": "^2.7.6",
36
- "mlly": "^1.4.0",
37
- "ohash": "^1.1.2",
37
+ "mlly": "^1.4.1",
38
+ "ohash": "^1.1.3",
38
39
  "pathe": "^1.1.1",
39
40
  "pify": "^6.1.0",
40
- "postcss": "^8.4.24",
41
+ "postcss": "^8.4.28",
41
42
  "postcss-import": "^15.1.0",
42
43
  "postcss-loader": "^7.3.3",
43
44
  "postcss-url": "^10.1.3",
44
45
  "pug-plain-loader": "^1.1.0",
45
- "std-env": "^3.3.3",
46
+ "std-env": "^3.4.3",
46
47
  "time-fix-plugin": "^2.0.7",
47
- "ufo": "^1.1.2",
48
- "unplugin": "^1.3.2",
48
+ "ufo": "^1.3.0",
49
+ "unplugin": "^1.4.0",
49
50
  "url-loader": "^4.1.1",
50
- "vue-bundle-renderer": "^1.0.3",
51
+ "vue-bundle-renderer": "^2.0.0",
51
52
  "vue-loader": "^17.2.2",
52
- "webpack": "^5.88.1",
53
+ "webpack": "^5.88.2",
53
54
  "webpack-bundle-analyzer": "^4.9.0",
54
55
  "webpack-dev-middleware": "^6.1.1",
55
56
  "webpack-hot-middleware": "^2.25.4",
56
57
  "webpack-virtual-modules": "^0.5.0",
57
58
  "webpackbar": "^5.0.2",
58
- "@nuxt/kit": "3.6.4"
59
+ "@nuxt/kit": "3.7.0"
59
60
  },
60
61
  "devDependencies": {
61
62
  "@types/fs-extra": "11.0.1",
62
63
  "@types/hash-sum": "1.0.0",
63
- "@types/lodash-es": "4.17.7",
64
+ "@types/lodash-es": "4.17.8",
64
65
  "@types/pify": "5.0.1",
65
66
  "@types/webpack-bundle-analyzer": "4.6.0",
66
67
  "@types/webpack-hot-middleware": "2.25.6",
67
68
  "@types/webpack-virtual-modules": "0.1.1",
68
69
  "unbuild": "latest",
69
70
  "vue": "3.3.4",
70
- "@nuxt/schema": "3.6.4"
71
+ "@nuxt/schema": "3.7.0"
71
72
  },
72
73
  "peerDependencies": {
73
74
  "vue": "^3.3.4"