@nuxt/webpack-builder 3.0.0-rc.0 → 3.0.0-rc.10

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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Nuxt } from '@nuxt/schema';
2
2
 
3
- declare function bundle(nuxt: Nuxt): Promise<unknown[]>;
3
+ declare function bundle(nuxt: Nuxt): Promise<unknown[] | undefined>;
4
4
 
5
5
  export { bundle };
package/dist/index.mjs CHANGED
@@ -1,79 +1,111 @@
1
1
  import pify from 'pify';
2
2
  import webpack from 'webpack';
3
+ import { promisifyHandler } from 'h3';
3
4
  import webpackDevMiddleware from 'webpack-dev-middleware';
4
5
  import webpackHotMiddleware from 'webpack-hot-middleware';
5
- import { joinURL } from 'ufo';
6
+ import { parseURL, parseQuery, joinURL } from 'ufo';
6
7
  import { useNuxt, logger, requireModule } from '@nuxt/kit';
8
+ import { pathToFileURL } from 'node:url';
7
9
  import { createUnplugin } from 'unplugin';
8
- import 'escape-string-regexp';
10
+ import { isAbsolute, relative, join, resolve, normalize, dirname } from 'pathe';
11
+ import { walk } from 'estree-walker';
9
12
  import MagicString from 'magic-string';
10
- import { join, resolve, dirname, isAbsolute } from 'pathe';
13
+ import { hash } from 'ohash';
11
14
  import { createFsFromVolume, Volume } from 'memfs';
12
15
  import VirtualModulesPlugin from 'webpack-virtual-modules';
13
16
  import querystring from 'node:querystring';
14
17
  import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
15
- import { cloneDeep, defaults, merge, uniq } from 'lodash-es';
18
+ import { cloneDeep, defaults as defaults$1, merge, uniq } from 'lodash-es';
16
19
  import TimeFixPlugin from 'time-fix-plugin';
17
20
  import WebpackBar from 'webpackbar';
18
21
  import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin';
22
+ import escapeRegExp from 'escape-string-regexp';
19
23
  import esbuildLoader from 'esbuild-loader';
20
24
  import MiniCssExtractPlugin from 'mini-css-extract-plugin';
21
25
  import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
22
26
  import { createCommonJS } from 'mlly';
23
27
  import VueLoaderPlugin from 'vue-loader/dist/pluginWebpack5.js';
24
- import hash from 'hash-sum';
28
+ import { normalizeWebpackManifest } from 'vue-bundle-renderer';
29
+ import hash$1 from 'hash-sum';
25
30
  import fse from 'fs-extra';
26
31
  import ForkTSCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
27
32
 
28
- const VITE_ASSET_RE = /^export default ["'](__VITE_ASSET.*)["']$/;
29
- const DynamicBasePlugin = createUnplugin(function(options = {}) {
33
+ const keyedFunctions = [
34
+ "useState",
35
+ "useFetch",
36
+ "useAsyncData",
37
+ "useLazyAsyncData",
38
+ "useLazyFetch"
39
+ ];
40
+ const KEYED_FUNCTIONS_RE = new RegExp(`(${keyedFunctions.join("|")})`);
41
+ const composableKeysPlugin = createUnplugin((options) => {
30
42
  return {
31
- name: "nuxt:dynamic-base-path",
32
- resolveId(id) {
33
- if (id.startsWith("/__NUXT_BASE__")) {
34
- return id.replace("/__NUXT_BASE__", "");
35
- }
36
- if (id === "#internal/nitro") {
37
- return "#internal/nitro";
38
- }
39
- return null;
40
- },
43
+ name: "nuxt:composable-keys",
41
44
  enforce: "post",
42
45
  transform(code, id) {
43
- const s = new MagicString(code);
44
- if (options.globalPublicPath && id.includes("paths.mjs") && code.includes("const appConfig = ")) {
45
- s.append(`${options.globalPublicPath} = buildAssetsURL();
46
- `);
47
- }
48
- const assetId = code.match(VITE_ASSET_RE);
49
- if (assetId) {
50
- s.overwrite(0, code.length, [
51
- "import { buildAssetsURL } from '#build/paths.mjs';",
52
- `export default buildAssetsURL("${assetId[1]}".replace("/__NUXT_BASE__", ""));`
53
- ].join("\n"));
54
- }
55
- if (!id.includes("paths.mjs") && code.includes("NUXT_BASE") && !code.includes("import { publicAssetsURL as __publicAssetsURL }")) {
56
- s.prepend("import { publicAssetsURL as __publicAssetsURL } from '#build/paths.mjs';\n");
46
+ const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href));
47
+ if (!pathname.match(/\.(m?[jt]sx?|vue)/) || parseQuery(search).type === "style") {
48
+ return;
57
49
  }
58
- if (id === "vite/preload-helper") {
59
- s.prepend("import { buildAssetsDir } from '#build/paths.mjs';\n");
60
- s.replace(/const base = ['"]\/__NUXT_BASE__\/['"]/, "const base = buildAssetsDir()");
61
- }
62
- s.replace(/from *['"]\/__NUXT_BASE__(\/[^'"]*)['"]/g, 'from "$1"');
63
- for (const delimiter of ["`", "'", '"']) {
64
- const delimiterRE = new RegExp(`(?<!(const base = |from *))${delimiter}([^${delimiter}]*)\\/__NUXT_BASE__\\/([^${delimiter}]*)${delimiter}`, "g");
65
- s.replace(delimiterRE, (r) => "`" + r.replace(/\/__NUXT_BASE__\//g, "${__publicAssetsURL()}").slice(1, -1) + "`");
50
+ if (!KEYED_FUNCTIONS_RE.test(code)) {
51
+ return;
66
52
  }
53
+ const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=<script[^>]*>)[\S\s.]*?(?=<\/script>)/) || [];
54
+ const s = new MagicString(code);
55
+ let count = 0;
56
+ const relativeID = isAbsolute(id) ? relative(options.rootDir, id) : id;
57
+ walk(this.parse(script, {
58
+ sourceType: "module",
59
+ ecmaVersion: "latest"
60
+ }), {
61
+ enter(_node) {
62
+ if (_node.type !== "CallExpression" || _node.callee.type !== "Identifier") {
63
+ return;
64
+ }
65
+ const node = _node;
66
+ if (keyedFunctions.includes(node.callee.name) && node.arguments.length < 4) {
67
+ const end = node.end;
68
+ s.appendLeft(
69
+ codeIndex + end - 1,
70
+ (node.arguments.length ? ", " : "") + "'$" + hash(`${relativeID}-${++count}`) + "'"
71
+ );
72
+ }
73
+ }
74
+ });
67
75
  if (s.hasChanged()) {
68
76
  return {
69
77
  code: s.toString(),
70
- map: s.generateMap({ source: id, includeContent: true })
78
+ map: options.sourcemap ? s.generateMap({ source: id, includeContent: true }) : void 0
71
79
  };
72
80
  }
73
81
  }
74
82
  };
75
83
  });
76
84
 
85
+ const defaults = {
86
+ globalPublicPath: "__webpack_public_path__",
87
+ sourcemap: true
88
+ };
89
+ const DynamicBasePlugin = createUnplugin((options = {}) => {
90
+ options = { ...defaults, ...options };
91
+ return {
92
+ name: "nuxt:dynamic-base-path",
93
+ enforce: "post",
94
+ transform(code, id) {
95
+ if (!id.includes("paths.mjs") || !code.includes("const appConfig = ")) {
96
+ return;
97
+ }
98
+ const s = new MagicString(code);
99
+ s.append(`${options.globalPublicPath} = buildAssetsURL();
100
+ `);
101
+ return {
102
+ code: s.toString(),
103
+ map: options.sourcemap ? s.generateMap({ source: id, includeContent: true }) : void 0
104
+ };
105
+ }
106
+ };
107
+ });
108
+
77
109
  function createMFS() {
78
110
  const fs = createFsFromVolume(new Volume());
79
111
  const _fs = { ...fs };
@@ -147,7 +179,11 @@ function getWebpackConfig(ctx) {
147
179
  const loaders = [];
148
180
  const { extend } = options.build;
149
181
  if (typeof extend === "function") {
150
- const extendedConfig = extend.call(builder, config, { loaders, ...ctx }) || config;
182
+ const extendedConfig = extend.call(
183
+ builder,
184
+ config,
185
+ { loaders, ...ctx }
186
+ ) || config;
151
187
  const pragma = /@|#/;
152
188
  const { devtool } = extendedConfig;
153
189
  if (typeof devtool === "string" && pragma.test(devtool)) {
@@ -160,34 +196,38 @@ function getWebpackConfig(ctx) {
160
196
  }
161
197
 
162
198
  function assets(ctx) {
163
- ctx.config.module.rules.push({
164
- test: /\.(png|jpe?g|gif|svg|webp)$/i,
165
- use: [{
166
- loader: "url-loader",
167
- options: {
168
- ...ctx.options.webpack.loaders.imgUrl,
169
- name: fileName(ctx, "img")
170
- }
171
- }]
172
- }, {
173
- test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
174
- use: [{
175
- loader: "url-loader",
176
- options: {
177
- ...ctx.options.webpack.loaders.fontUrl,
178
- name: fileName(ctx, "font")
179
- }
180
- }]
181
- }, {
182
- test: /\.(webm|mp4|ogv)$/i,
183
- use: [{
184
- loader: "file-loader",
185
- options: {
186
- ...ctx.options.webpack.loaders.file,
187
- name: fileName(ctx, "video")
188
- }
189
- }]
190
- });
199
+ ctx.config.module.rules.push(
200
+ {
201
+ test: /\.(png|jpe?g|gif|svg|webp)$/i,
202
+ use: [{
203
+ loader: "url-loader",
204
+ options: {
205
+ ...ctx.options.webpack.loaders.imgUrl,
206
+ name: fileName(ctx, "img")
207
+ }
208
+ }]
209
+ },
210
+ {
211
+ test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
212
+ use: [{
213
+ loader: "url-loader",
214
+ options: {
215
+ ...ctx.options.webpack.loaders.fontUrl,
216
+ name: fileName(ctx, "font")
217
+ }
218
+ }]
219
+ },
220
+ {
221
+ test: /\.(webm|mp4|ogv)$/i,
222
+ use: [{
223
+ loader: "file-loader",
224
+ options: {
225
+ ...ctx.options.webpack.loaders.file,
226
+ name: fileName(ctx, "video")
227
+ }
228
+ }]
229
+ }
230
+ );
191
231
  }
192
232
 
193
233
  class WarningIgnorePlugin {
@@ -206,7 +246,8 @@ function base(ctx) {
206
246
  baseAlias,
207
247
  baseConfig,
208
248
  basePlugins,
209
- baseResolve
249
+ baseResolve,
250
+ baseTranspile
210
251
  ]);
211
252
  }
212
253
  function baseConfig(ctx) {
@@ -231,6 +272,7 @@ function baseConfig(ctx) {
231
272
  }
232
273
  function basePlugins(ctx) {
233
274
  const { config, options, nuxt } = ctx;
275
+ config.plugins = config.plugins || [];
234
276
  if (options.dev) {
235
277
  config.plugins.push(new TimeFixPlugin());
236
278
  }
@@ -238,11 +280,13 @@ function basePlugins(ctx) {
238
280
  config.plugins.push(new WarningIgnorePlugin(getWarningIgnoreFilter(ctx)));
239
281
  config.plugins.push(new webpack.DefinePlugin(getEnv(ctx)));
240
282
  if (ctx.isServer || ctx.isDev && !options.build.quiet && options.webpack.friendlyErrors) {
241
- ctx.config.plugins.push(new FriendlyErrorsWebpackPlugin({
242
- clearConsole: false,
243
- reporter: "consola",
244
- logLevel: "ERROR"
245
- }));
283
+ config.plugins.push(
284
+ new FriendlyErrorsWebpackPlugin({
285
+ clearConsole: false,
286
+ reporter: "consola",
287
+ logLevel: "ERROR"
288
+ })
289
+ );
246
290
  }
247
291
  if (nuxt.options.webpack.profile) {
248
292
  const colors = {
@@ -306,6 +350,25 @@ function baseResolve(ctx) {
306
350
  ...config.resolveLoader
307
351
  };
308
352
  }
353
+ function baseTranspile(ctx) {
354
+ const { options } = ctx;
355
+ const transpile = [
356
+ /\.vue\.js/i,
357
+ /consola\/src/,
358
+ /vue-demi/
359
+ ];
360
+ for (let pattern of options.build.transpile) {
361
+ if (typeof pattern === "function") {
362
+ pattern = pattern(ctx);
363
+ }
364
+ if (typeof pattern === "string") {
365
+ transpile.push(new RegExp(escapeRegExp(normalize(pattern))));
366
+ } else if (pattern instanceof RegExp) {
367
+ transpile.push(pattern);
368
+ }
369
+ }
370
+ ctx.transpile = [...transpile, ...ctx.transpile];
371
+ }
309
372
  function getCache(ctx) {
310
373
  const { options } = ctx;
311
374
  if (!options.dev) {
@@ -315,7 +378,7 @@ function getCache(ctx) {
315
378
  function getOutput(ctx) {
316
379
  const { options } = ctx;
317
380
  return {
318
- path: resolve(options.buildDir, "dist", ctx.isServer ? "server" : "client"),
381
+ path: resolve(options.buildDir, "dist", ctx.isServer ? "server" : joinURL("client", options.app.buildAssetsDir)),
319
382
  filename: fileName(ctx, "app"),
320
383
  chunkFilename: fileName(ctx, "chunk"),
321
384
  publicPath: joinURL(options.app.baseURL, options.app.buildAssetsDir)
@@ -357,31 +420,34 @@ function esbuild(ctx) {
357
420
  const { config } = ctx;
358
421
  const target = ctx.isServer ? "es2019" : "chrome85";
359
422
  config.optimization.minimizer.push(new esbuildLoader.ESBuildMinifyPlugin());
360
- config.module.rules.push({
361
- test: /\.m?[jt]s$/i,
362
- loader: "esbuild-loader",
363
- exclude: (file) => {
364
- file = file.split("node_modules", 2)[1];
365
- if (!file) {
366
- return false;
423
+ config.module.rules.push(
424
+ {
425
+ test: /\.m?[jt]s$/i,
426
+ loader: "esbuild-loader",
427
+ exclude: (file) => {
428
+ file = file.split("node_modules", 2)[1];
429
+ if (!file) {
430
+ return false;
431
+ }
432
+ return !ctx.transpile.some((module) => module.test(file));
433
+ },
434
+ resolve: {
435
+ fullySpecified: false
436
+ },
437
+ options: {
438
+ loader: "ts",
439
+ target
367
440
  }
368
- return !ctx.transpile.some((module) => module.test(file));
369
- },
370
- resolve: {
371
- fullySpecified: false
372
441
  },
373
- options: {
374
- loader: "ts",
375
- target
376
- }
377
- }, {
378
- test: /\.m?[jt]sx$/,
379
- loader: "esbuild-loader",
380
- options: {
381
- loader: "tsx",
382
- target
442
+ {
443
+ test: /\.m?[jt]sx$/,
444
+ loader: "esbuild-loader",
445
+ options: {
446
+ loader: "tsx",
447
+ target
448
+ }
383
449
  }
384
- });
450
+ );
385
451
  }
386
452
 
387
453
  function pug(ctx) {
@@ -460,7 +526,7 @@ const getPostcssConfig = (nuxt) => {
460
526
  if (!nuxt.options.webpack.postcss || !nuxt.options.postcss) {
461
527
  return false;
462
528
  }
463
- const configFile = nuxt.options.postcss?.config;
529
+ const configFile = nuxt.options.postcss.config;
464
530
  if (configFile) {
465
531
  return {
466
532
  postcssOptions: {
@@ -472,7 +538,7 @@ const getPostcssConfig = (nuxt) => {
472
538
  let postcssOptions = cloneDeep(nuxt.options.postcss);
473
539
  if (isPureObject(postcssOptions)) {
474
540
  if (Array.isArray(postcssOptions.plugins)) {
475
- defaults(postcssOptions, defaultConfig());
541
+ defaults$1(postcssOptions, defaultConfig());
476
542
  } else {
477
543
  postcssOptions = merge({}, defaultConfig(), postcssOptions);
478
544
  loadPlugins(postcssOptions);
@@ -507,7 +573,7 @@ function extractCSS(ctx) {
507
573
  config.plugins.push(new MiniCssExtractPlugin({
508
574
  filename: fileName(ctx, "css"),
509
575
  chunkFilename: fileName(ctx, "css"),
510
- ...options.webpack.extractCSS
576
+ ...options.webpack.extractCSS === true ? {} : options.webpack.extractCSS
511
577
  }));
512
578
  }
513
579
  }
@@ -564,10 +630,6 @@ function createCssLoadersRule(ctx, cssLoaderOptions) {
564
630
  ];
565
631
  }
566
632
  return [
567
- {
568
- loader: "vue-style-loader",
569
- options: options.webpack.loaders.vueStyle
570
- },
571
633
  cssLoader
572
634
  ];
573
635
  }
@@ -591,17 +653,19 @@ const validate = (compiler) => {
591
653
  logger.warn('webpack config `target` should be "node".');
592
654
  }
593
655
  if (!compiler.options.externals) {
594
- logger.info("It is recommended to externalize dependencies in the server build for better build performance.");
656
+ logger.info(
657
+ "It is recommended to externalize dependencies in the server build for better build performance."
658
+ );
595
659
  }
596
660
  };
597
661
  const isJSRegExp = /\.[cm]?js(\?[^.]+)?$/;
598
662
  const isJS = (file) => isJSRegExp.test(file);
599
- const extractQueryPartJS = (file) => isJSRegExp.exec(file)[1];
663
+ const extractQueryPartJS = (file) => isJSRegExp.exec(file)?.[1];
600
664
  const isCSS = (file) => /\.css(\?[^.]+)?$/.test(file);
601
665
  const isHotUpdate = (file) => file.includes("hot-update");
602
666
 
603
667
  class VueSSRClientPlugin {
604
- constructor(options = {}) {
668
+ constructor(options) {
605
669
  this.options = Object.assign({
606
670
  filename: null
607
671
  }, options);
@@ -613,14 +677,14 @@ class VueSSRClientPlugin {
613
677
  const initialFiles = uniq(Object.keys(stats.entrypoints).map((name) => stats.entrypoints[name].assets).reduce((files, entryAssets) => files.concat(entryAssets.map((entryAsset) => entryAsset.name)), []).filter((file) => isJS(file) || isCSS(file))).filter((file) => !isHotUpdate(file));
614
678
  const asyncFiles = allFiles.filter((file) => isJS(file) || isCSS(file)).filter((file) => !initialFiles.includes(file)).filter((file) => !isHotUpdate(file));
615
679
  const assetsMapping = {};
616
- stats.assets.filter(({ name }) => isJS(name)).filter(({ name }) => !isHotUpdate(name)).forEach(({ name, chunkNames }) => {
617
- const componentHash = hash(chunkNames.join("|"));
680
+ stats.assets.filter(({ name }) => isJS(name)).filter(({ name }) => !isHotUpdate(name)).forEach(({ name, chunkNames = [] }) => {
681
+ const componentHash = hash$1(chunkNames.join("|"));
618
682
  if (!assetsMapping[componentHash]) {
619
683
  assetsMapping[componentHash] = [];
620
684
  }
621
685
  assetsMapping[componentHash].push(name);
622
686
  });
623
- const manifest = {
687
+ const webpackManifest = {
624
688
  publicPath: stats.publicPath,
625
689
  all: allFiles,
626
690
  initial: initialFiles,
@@ -628,9 +692,9 @@ class VueSSRClientPlugin {
628
692
  modules: {},
629
693
  assetsMapping
630
694
  };
631
- const { entrypoints, namedChunkGroups } = stats;
695
+ const { entrypoints = {}, namedChunkGroups = {} } = stats;
632
696
  const assetModules = stats.modules.filter((m) => m.assets.length);
633
- const fileToIndex = (file) => manifest.all.indexOf(file);
697
+ const fileToIndex = (file) => webpackManifest.all.indexOf(file);
634
698
  stats.modules.forEach((m) => {
635
699
  if (m.chunks.length === 1) {
636
700
  const [cid] = m.chunks;
@@ -651,12 +715,12 @@ class VueSSRClientPlugin {
651
715
  }
652
716
  }
653
717
  const files = Array.from(filesSet);
654
- manifest.modules[hash(id)] = files;
718
+ webpackManifest.modules[hash$1(id)] = files;
655
719
  if (Array.isArray(m.modules)) {
656
720
  for (const concatenatedModule of m.modules) {
657
- const id2 = hash(concatenatedModule.identifier.replace(/\s\w+$/, ""));
658
- if (!manifest.modules[id2]) {
659
- manifest.modules[id2] = files;
721
+ const id2 = hash$1(concatenatedModule.identifier.replace(/\s\w+$/, ""));
722
+ if (!webpackManifest.modules[id2]) {
723
+ webpackManifest.modules[id2] = files;
660
724
  }
661
725
  }
662
726
  }
@@ -667,6 +731,8 @@ class VueSSRClientPlugin {
667
731
  });
668
732
  }
669
733
  });
734
+ const manifest = normalizeWebpackManifest(webpackManifest);
735
+ await this.options.nuxt.callHook("build:manifest", manifest);
670
736
  const src = JSON.stringify(manifest, null, 2);
671
737
  await fse.mkdirp(dirname(this.options.filename));
672
738
  await fse.writeFile(this.options.filename, src);
@@ -697,11 +763,15 @@ class VueSSRServerPlugin {
697
763
  }
698
764
  const entryAssets = entryInfo.assets.filter((asset) => isJS(asset.name));
699
765
  if (entryAssets.length > 1) {
700
- throw new Error("Server-side bundle should have one single entry file. Avoid using CommonsChunkPlugin in the server config.");
766
+ throw new Error(
767
+ "Server-side bundle should have one single entry file. Avoid using CommonsChunkPlugin in the server config."
768
+ );
701
769
  }
702
770
  const [entry] = entryAssets;
703
771
  if (!entry || typeof entry.name !== "string") {
704
- throw new Error(`Entry "${entryName}" not found. Did you specify the correct entry option?`);
772
+ throw new Error(
773
+ `Entry "${entryName}" not found. Did you specify the correct entry option?`
774
+ );
705
775
  }
706
776
  const bundle = {
707
777
  entry: entry.name,
@@ -752,7 +822,8 @@ function vue(ctx) {
752
822
  });
753
823
  if (ctx.isClient) {
754
824
  config.plugins.push(new VueSSRClientPlugin({
755
- filename: resolve(options.buildDir, "dist/server", `${ctx.name}.manifest.json`)
825
+ filename: resolve(options.buildDir, "dist/server", `${ctx.name}.manifest.json`),
826
+ nuxt: ctx.nuxt
756
827
  }));
757
828
  } else {
758
829
  config.plugins.push(new VueSSRServerPlugin({
@@ -789,10 +860,14 @@ function client(ctx) {
789
860
  ]);
790
861
  }
791
862
  function clientDevtool(ctx) {
792
- if (!ctx.isDev) {
863
+ if (!ctx.nuxt.options.sourcemap.client) {
793
864
  ctx.config.devtool = false;
794
865
  return;
795
866
  }
867
+ if (!ctx.isDev) {
868
+ ctx.config.devtool = "source-map";
869
+ return;
870
+ }
796
871
  const scriptPolicy = getCspScriptPolicy(ctx);
797
872
  const noUnsafeEval = scriptPolicy && !scriptPolicy.includes("'unsafe-eval'");
798
873
  ctx.config.devtool = noUnsafeEval ? "cheap-module-source-map" : "eval-cheap-module-source-map";
@@ -821,7 +896,10 @@ function clientHMR(ctx) {
821
896
  };
822
897
  const hotMiddlewareClientOptionsStr = querystring.stringify(hotMiddlewareClientOptions);
823
898
  const app = config.entry.app;
824
- app.unshift(`webpack-hot-middleware/client?${hotMiddlewareClientOptionsStr}`);
899
+ app.unshift(
900
+ `webpack-hot-middleware/client?${hotMiddlewareClientOptionsStr}`
901
+ );
902
+ config.plugins = config.plugins || [];
825
903
  config.plugins.push(new webpack.HotModuleReplacementPlugin());
826
904
  }
827
905
  function clientOptimization(_ctx) {
@@ -897,7 +975,7 @@ function server(ctx) {
897
975
  function serverPreset(ctx) {
898
976
  const { config } = ctx;
899
977
  config.output.filename = "server.mjs";
900
- config.devtool = "cheap-module-source-map";
978
+ config.devtool = ctx.nuxt.options.sourcemap.server ? ctx.isDev ? "cheap-module-source-map" : "source-map" : false;
901
979
  config.optimization = {
902
980
  splitChunks: false,
903
981
  minimize: false
@@ -921,17 +999,21 @@ function serverStandalone(ctx) {
921
999
  return;
922
1000
  }
923
1001
  ctx.config.externals.push(({ request }, cb) => {
1002
+ if (!request) {
1003
+ return cb(void 0, false);
1004
+ }
924
1005
  if (external.includes(request)) {
925
- return cb(null, true);
1006
+ return cb(void 0, true);
926
1007
  }
927
1008
  if (request[0] === "." || isAbsolute(request) || inline.find((prefix) => typeof prefix === "string" && request.startsWith(prefix)) || assetPattern.test(request)) {
928
- return cb(null, false);
1009
+ return cb(void 0, false);
929
1010
  }
930
- return cb(null, true);
1011
+ return cb(void 0, true);
931
1012
  });
932
1013
  }
933
1014
  function serverPlugins(ctx) {
934
1015
  const { config, options } = ctx;
1016
+ config.plugins = config.plugins || [];
935
1017
  if (options.webpack.serverURLPolyfill) {
936
1018
  config.plugins.push(new webpack.ProvidePlugin({
937
1019
  URL: [options.webpack.serverURLPolyfill, "URL"],
@@ -939,12 +1021,12 @@ function serverPlugins(ctx) {
939
1021
  }));
940
1022
  }
941
1023
  if (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev) {
942
- ctx.config.plugins.push(new ForkTSCheckerWebpackPlugin({ logger }));
1024
+ config.plugins.push(new ForkTSCheckerWebpackPlugin({ logger }));
943
1025
  }
944
1026
  }
945
1027
 
946
1028
  async function bundle(nuxt) {
947
- await registerVirtualModules();
1029
+ registerVirtualModules();
948
1030
  const webpackConfigs = [client, ...nuxt.options.ssr ? [server] : []].map((preset) => {
949
1031
  const ctx = createWebpackConfigContext(nuxt);
950
1032
  applyPresets(ctx, preset);
@@ -954,7 +1036,11 @@ async function bundle(nuxt) {
954
1036
  const mfs = nuxt.options.dev ? createMFS() : null;
955
1037
  const compilers = webpackConfigs.map((config) => {
956
1038
  config.plugins.push(DynamicBasePlugin.webpack({
957
- globalPublicPath: "__webpack_public_path__"
1039
+ sourcemap: nuxt.options.sourcemap[config.name]
1040
+ }));
1041
+ config.plugins.push(composableKeysPlugin.webpack({
1042
+ sourcemap: nuxt.options.sourcemap[config.name],
1043
+ rootDir: nuxt.options.rootDir
958
1044
  }));
959
1045
  const compiler = webpack(config);
960
1046
  if (nuxt.options.dev) {
@@ -993,8 +1079,9 @@ async function createDevMiddleware(compiler) {
993
1079
  }));
994
1080
  await nuxt.callHook("webpack:devMiddleware", devMiddleware);
995
1081
  await nuxt.callHook("webpack:hotMiddleware", hotMiddleware);
1082
+ const handlers = [promisifyHandler(devMiddleware), promisifyHandler(hotMiddleware)];
996
1083
  await nuxt.callHook("server:devMiddleware", async (req, res, next) => {
997
- for (const mw of [devMiddleware, hotMiddleware]) {
1084
+ for (const mw of handlers) {
998
1085
  await mw?.(req, res);
999
1086
  }
1000
1087
  next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/webpack-builder",
3
- "version": "3.0.0-rc.0",
3
+ "version": "3.0.0-rc.10",
4
4
  "repository": "nuxt/framework",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,56 +16,59 @@
16
16
  "prepack": "unbuild"
17
17
  },
18
18
  "dependencies": {
19
- "@babel/core": "^7.17.9",
19
+ "@babel/core": "^7.19.0",
20
20
  "@nuxt/friendly-errors-webpack-plugin": "^2.5.2",
21
- "@nuxt/kit": "3.0.0-rc.0",
22
- "autoprefixer": "^10.4.4",
21
+ "@nuxt/kit": "3.0.0-rc.10",
22
+ "autoprefixer": "^10.4.10",
23
23
  "css-loader": "^6.7.1",
24
- "css-minimizer-webpack-plugin": "^3.4.1",
25
- "cssnano": "^5.1.7",
26
- "esbuild-loader": "^2.18.0",
24
+ "css-minimizer-webpack-plugin": "^4.1.0",
25
+ "cssnano": "^5.1.13",
26
+ "esbuild-loader": "^2.20.0",
27
27
  "escape-string-regexp": "^5.0.0",
28
+ "estree-walker": "^3.0.1",
28
29
  "file-loader": "^6.2.0",
29
- "fork-ts-checker-webpack-plugin": "^7.2.6",
30
+ "fork-ts-checker-webpack-plugin": "^7.2.13",
30
31
  "fs-extra": "^10.1.0",
31
32
  "hash-sum": "^2.0.0",
32
33
  "lodash-es": "^4.17.21",
33
- "magic-string": "^0.26.1",
34
- "memfs": "^3.4.1",
35
- "mini-css-extract-plugin": "^2.6.0",
36
- "mlly": "^0.5.2",
37
- "pathe": "^0.2.0",
38
- "pify": "^5.0.0",
39
- "postcss": "^8.4.12",
40
- "postcss-import": "^14.1.0",
41
- "postcss-loader": "^6.2.1",
34
+ "magic-string": "^0.26.3",
35
+ "memfs": "^3.4.7",
36
+ "mini-css-extract-plugin": "^2.6.1",
37
+ "mlly": "^0.5.14",
38
+ "ohash": "^0.1.5",
39
+ "pathe": "^0.3.7",
40
+ "pify": "^6.1.0",
41
+ "postcss": "^8.4.16",
42
+ "postcss-import": "^15.0.0",
43
+ "postcss-loader": "^7.0.1",
42
44
  "postcss-url": "^10.1.3",
43
45
  "style-resources-loader": "^1.5.0",
44
46
  "time-fix-plugin": "^2.0.7",
45
- "ufo": "^0.8.3",
46
- "unplugin": "^0.6.2",
47
+ "ufo": "^0.8.5",
48
+ "unplugin": "^0.9.2",
47
49
  "url-loader": "^4.1.1",
50
+ "vue-bundle-renderer": "^0.4.2",
48
51
  "vue-loader": "^17.0.0",
49
- "vue-style-loader": "^4.1.3",
50
- "webpack": "^5.72.0",
51
- "webpack-bundle-analyzer": "^4.5.0",
52
- "webpack-dev-middleware": "^5.3.1",
53
- "webpack-hot-middleware": "^2.25.1",
54
- "webpack-virtual-modules": "^0.4.3",
52
+ "webpack": "^5.74.0",
53
+ "webpack-bundle-analyzer": "^4.6.1",
54
+ "webpack-dev-middleware": "^5.3.3",
55
+ "webpack-hot-middleware": "^2.25.2",
56
+ "webpack-virtual-modules": "^0.4.4",
55
57
  "webpackbar": "^5.0.2"
56
58
  },
57
59
  "devDependencies": {
58
- "@nuxt/schema": "3.0.0-rc.0",
60
+ "@nuxt/schema": "3.0.0-rc.10",
61
+ "@types/lodash-es": "^4.17.6",
59
62
  "@types/pify": "^5.0.1",
60
- "@types/webpack-bundle-analyzer": "^4.4.1",
63
+ "@types/webpack-bundle-analyzer": "^4.4.2",
61
64
  "@types/webpack-dev-middleware": "^5.0.2",
62
65
  "@types/webpack-hot-middleware": "^2.25.6",
63
66
  "@types/webpack-virtual-modules": "^0",
64
67
  "unbuild": "latest",
65
- "vue": "3.2.33"
68
+ "vue": "3.2.39"
66
69
  },
67
70
  "peerDependencies": {
68
- "vue": "3.2.33"
71
+ "vue": "^3.2.39"
69
72
  },
70
73
  "engines": {
71
74
  "node": "^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0"