@nuxt/webpack-builder 3.12.3 → 3.12.4

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 +2 -2
  2. package/dist/index.mjs +53 -62
  3. package/package.json +10 -10
package/README.md CHANGED
@@ -34,7 +34,7 @@ It provides a number of features that make it easy to build fast, SEO-friendly,
34
34
  - 🏠 [Local Development](#local-development)
35
35
  - ⛰️ [Nuxt 2](#nuxt-2)
36
36
  - 🛟 [Professional Support](#professional-support)
37
- - 🔗 [Follow us](#follow-us)
37
+ - 🔗 [Follow Us](#follow-us)
38
38
  - ⚖️ [License](#license)
39
39
 
40
40
  ---
@@ -106,7 +106,7 @@ Follow the docs to [Set Up Your Local Development Environment](https://nuxt.com/
106
106
  - Technical audit & consulting: [Nuxt Experts](https://nuxt.com/enterprise/support)
107
107
  - Custom development & more: [Nuxt Agencies Partners](https://nuxt.com/enterprise/agencies)
108
108
 
109
- ## <a name="follow-us">🔗 Follow us</a>
109
+ ## <a name="follow-us">🔗 Follow Us</a>
110
110
 
111
111
  <p valign="center">
112
112
  <a href="https://chat.nuxt.dev"><img width="20px" src="https://github.com/nuxt/nuxt/tree/main/.github/assets/discord.svg" alt="Discord"></a>&nbsp;&nbsp;<a href="https://twitter.nuxt.dev"><img width="20px" src="https://github.com/nuxt/nuxt/tree/main/.github/assets/twitter.svg" alt="Twitter"></a>&nbsp;&nbsp;<a href="https://github.nuxt.dev"><img width="20px" src="https://github.com/nuxt/nuxt/tree/main/.github/assets/github.svg" alt="GitHub"></a>
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import webpackDevMiddleware from 'webpack-dev-middleware';
5
5
  import webpackHotMiddleware from 'webpack-hot-middleware';
6
6
  import { defu } from 'defu';
7
7
  import { parseURL, parseQuery, joinURL } from 'ufo';
8
- import { useNuxt, logger, requireModule } from '@nuxt/kit';
8
+ import { useNuxt, logger, tryResolveModule, requireModule } from '@nuxt/kit';
9
9
  import { pathToFileURL, fileURLToPath } from 'node:url';
10
10
  import { createUnplugin } from 'unplugin';
11
11
  import { isAbsolute, relative, join, resolve, normalize, dirname } from 'pathe';
@@ -13,7 +13,7 @@ import { walk } from 'estree-walker';
13
13
  import MagicString from 'magic-string';
14
14
  import { hash } from 'ohash';
15
15
  import escapeRE from 'escape-string-regexp';
16
- import { findStaticImports, parseStaticImport } from 'mlly';
16
+ import { findStaticImports, parseStaticImport, interopDefault } from 'mlly';
17
17
  import { createFsFromVolume, Volume } from 'memfs';
18
18
  import VirtualModulesPlugin from 'webpack-virtual-modules';
19
19
  import querystring from 'node:querystring';
@@ -370,12 +370,12 @@ function createWebpackConfigContext(nuxt) {
370
370
  transpile: []
371
371
  };
372
372
  }
373
- function applyPresets(ctx, presets) {
373
+ async function applyPresets(ctx, presets) {
374
374
  for (const preset of toArray(presets)) {
375
375
  if (Array.isArray(preset)) {
376
- preset[0](ctx, preset[1]);
376
+ await preset[0](ctx, preset[1]);
377
377
  } else {
378
- preset(ctx);
378
+ await preset(ctx);
379
379
  }
380
380
  }
381
381
  }
@@ -449,8 +449,8 @@ class WarningIgnorePlugin {
449
449
  }
450
450
  }
451
451
 
452
- function base(ctx) {
453
- applyPresets(ctx, [
452
+ async function base(ctx) {
453
+ await applyPresets(ctx, [
454
454
  baseAlias,
455
455
  baseConfig,
456
456
  basePlugins,
@@ -694,29 +694,11 @@ function pug(ctx) {
694
694
  }
695
695
 
696
696
  const isPureObject = (obj) => obj !== null && !Array.isArray(obj) && typeof obj === "object";
697
- const ensureItemIsLast = (item) => (arr) => {
698
- const index = arr.indexOf(item);
699
- if (index !== -1) {
700
- arr.splice(index, 1);
701
- arr.push(item);
702
- }
703
- return arr;
704
- };
705
- const orderPresets = {
706
- cssnanoLast: ensureItemIsLast("cssnano"),
707
- autoprefixerLast: ensureItemIsLast("autoprefixer"),
708
- autoprefixerAndCssnanoLast(names) {
709
- return orderPresets.cssnanoLast(orderPresets.autoprefixerLast(names));
710
- }
711
- };
712
- const getPostcssConfig = (nuxt) => {
713
- function sortPlugins({ plugins, order }) {
714
- const names = Object.keys(plugins);
715
- if (typeof order === "string") {
716
- order = orderPresets[order];
717
- }
718
- return typeof order === "function" ? order(names, orderPresets) : order || names;
719
- }
697
+ function sortPlugins({ plugins, order }) {
698
+ const names = Object.keys(plugins);
699
+ return typeof order === "function" ? order(names) : order || names;
700
+ }
701
+ async function getPostcssConfig(nuxt) {
720
702
  if (!nuxt.options.webpack.postcss || !nuxt.options.postcss) {
721
703
  return false;
722
704
  }
@@ -736,30 +718,39 @@ const getPostcssConfig = (nuxt) => {
736
718
  */
737
719
  "postcss-url": {}
738
720
  },
739
- sourceMap: nuxt.options.webpack.cssSourceMap,
740
- // Array, String or Function
741
- order: "autoprefixerAndCssnanoLast"
721
+ sourceMap: nuxt.options.webpack.cssSourceMap
742
722
  });
743
723
  if (!Array.isArray(postcssOptions.plugins) && isPureObject(postcssOptions.plugins)) {
744
724
  const cwd = fileURLToPath(new URL(".", import.meta.url));
745
- postcssOptions.plugins = sortPlugins(postcssOptions).map((pluginName) => {
746
- const pluginFn = requireModule(pluginName, { paths: [cwd] });
725
+ const plugins = [];
726
+ for (const pluginName of sortPlugins(postcssOptions)) {
747
727
  const pluginOptions = postcssOptions.plugins[pluginName];
748
- if (!pluginOptions || typeof pluginFn !== "function") {
749
- return null;
728
+ if (!pluginOptions) {
729
+ continue;
750
730
  }
751
- return pluginFn(pluginOptions);
752
- }).filter(Boolean);
731
+ const path = await tryResolveModule(pluginName, nuxt.options.modulesDir);
732
+ let pluginFn;
733
+ if (path) {
734
+ pluginFn = await import(pathToFileURL(path).href).then(interopDefault);
735
+ } else {
736
+ console.warn(`[nuxt] could not import postcss plugin \`${pluginName}\` with ESM. Please report this as a bug.`);
737
+ pluginFn = requireModule(pluginName, { paths: [cwd] });
738
+ }
739
+ if (typeof pluginFn === "function") {
740
+ plugins.push(pluginFn(pluginOptions));
741
+ }
742
+ }
743
+ postcssOptions.plugins = plugins;
753
744
  }
754
745
  return {
755
746
  sourceMap: nuxt.options.webpack.cssSourceMap,
756
747
  ...nuxt.options.webpack.postcss,
757
748
  postcssOptions
758
749
  };
759
- };
750
+ }
760
751
 
761
- function style(ctx) {
762
- applyPresets(ctx, [
752
+ async function style(ctx) {
753
+ await applyPresets(ctx, [
763
754
  loaders,
764
755
  extractCSS,
765
756
  minimizer
@@ -784,21 +775,21 @@ function extractCSS(ctx) {
784
775
  ...config === true ? {} : config
785
776
  }));
786
777
  }
787
- function loaders(ctx) {
788
- ctx.config.module.rules.push(createdStyleRule("css", /\.css$/i, null, ctx));
789
- ctx.config.module.rules.push(createdStyleRule("postcss", /\.p(ost)?css$/i, null, ctx));
778
+ async function loaders(ctx) {
779
+ ctx.config.module.rules.push(await createdStyleRule("css", /\.css$/i, null, ctx));
780
+ ctx.config.module.rules.push(await createdStyleRule("postcss", /\.p(ost)?css$/i, null, ctx));
790
781
  const lessLoader = { loader: "less-loader", options: ctx.userConfig.loaders.less };
791
- ctx.config.module.rules.push(createdStyleRule("less", /\.less$/i, lessLoader, ctx));
782
+ ctx.config.module.rules.push(await createdStyleRule("less", /\.less$/i, lessLoader, ctx));
792
783
  const sassLoader = { loader: "sass-loader", options: ctx.userConfig.loaders.sass };
793
- ctx.config.module.rules.push(createdStyleRule("sass", /\.sass$/i, sassLoader, ctx));
784
+ ctx.config.module.rules.push(await createdStyleRule("sass", /\.sass$/i, sassLoader, ctx));
794
785
  const scssLoader = { loader: "sass-loader", options: ctx.userConfig.loaders.scss };
795
- ctx.config.module.rules.push(createdStyleRule("scss", /\.scss$/i, scssLoader, ctx));
786
+ ctx.config.module.rules.push(await createdStyleRule("scss", /\.scss$/i, scssLoader, ctx));
796
787
  const stylusLoader = { loader: "stylus-loader", options: ctx.userConfig.loaders.stylus };
797
- ctx.config.module.rules.push(createdStyleRule("stylus", /\.styl(us)?$/i, stylusLoader, ctx));
788
+ ctx.config.module.rules.push(await createdStyleRule("stylus", /\.styl(us)?$/i, stylusLoader, ctx));
798
789
  }
799
- function createdStyleRule(lang, test, processorLoader, ctx) {
790
+ async function createdStyleRule(lang, test, processorLoader, ctx) {
800
791
  const styleLoaders = [
801
- createPostcssLoadersRule(ctx),
792
+ await createPostcssLoadersRule(ctx),
802
793
  processorLoader
803
794
  ].filter(Boolean);
804
795
  ctx.userConfig.loaders.css.importLoaders = ctx.userConfig.loaders.cssModules.importLoaders = styleLoaders.length;
@@ -844,11 +835,11 @@ function createCssLoadersRule(ctx, cssLoaderOptions) {
844
835
  cssLoader
845
836
  ];
846
837
  }
847
- function createPostcssLoadersRule(ctx) {
838
+ async function createPostcssLoadersRule(ctx) {
848
839
  if (!ctx.options.postcss) {
849
840
  return;
850
841
  }
851
- const config = getPostcssConfig(ctx.nuxt);
842
+ const config = await getPostcssConfig(ctx.nuxt);
852
843
  if (!config) {
853
844
  return;
854
845
  }
@@ -1076,8 +1067,8 @@ function vue(ctx) {
1076
1067
  }));
1077
1068
  }
1078
1069
 
1079
- function nuxt(ctx) {
1080
- applyPresets(ctx, [
1070
+ async function nuxt(ctx) {
1071
+ await applyPresets(ctx, [
1081
1072
  base,
1082
1073
  assets,
1083
1074
  esbuild,
@@ -1087,10 +1078,10 @@ function nuxt(ctx) {
1087
1078
  ]);
1088
1079
  }
1089
1080
 
1090
- function client(ctx) {
1081
+ async function client(ctx) {
1091
1082
  ctx.name = "client";
1092
1083
  ctx.isClient = true;
1093
- applyPresets(ctx, [
1084
+ await applyPresets(ctx, [
1094
1085
  nuxt,
1095
1086
  clientPlugins,
1096
1087
  clientOptimization,
@@ -1212,10 +1203,10 @@ function node(ctx) {
1212
1203
  }
1213
1204
 
1214
1205
  const assetPattern = /\.(?:css|s[ca]ss|png|jpe?g|gif|svg|woff2?|eot|ttf|otf|webp|webm|mp4|ogv)(?:\?.*)?$/i;
1215
- function server(ctx) {
1206
+ async function server(ctx) {
1216
1207
  ctx.name = "server";
1217
1208
  ctx.isServer = true;
1218
- applyPresets(ctx, [
1209
+ await applyPresets(ctx, [
1219
1210
  nuxt,
1220
1211
  node,
1221
1212
  serverStandalone,
@@ -1287,12 +1278,12 @@ function serverPlugins(ctx) {
1287
1278
 
1288
1279
  const bundle = async (nuxt) => {
1289
1280
  registerVirtualModules();
1290
- const webpackConfigs = [client, ...nuxt.options.ssr ? [server] : []].map((preset) => {
1281
+ const webpackConfigs = await Promise.all([client, ...nuxt.options.ssr ? [server] : []].map(async (preset) => {
1291
1282
  const ctx = createWebpackConfigContext(nuxt);
1292
1283
  ctx.userConfig = defu(nuxt.options.webpack[`$${preset.name}`], ctx.userConfig);
1293
- applyPresets(ctx, preset);
1284
+ await applyPresets(ctx, preset);
1294
1285
  return getWebpackConfig(ctx);
1295
- });
1286
+ }));
1296
1287
  await nuxt.callHook("webpack:config", webpackConfigs);
1297
1288
  const mfs = nuxt.options.dev ? createMFS() : null;
1298
1289
  for (const config of webpackConfigs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/webpack-builder",
3
- "version": "3.12.3",
3
+ "version": "3.12.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -26,9 +26,9 @@
26
26
  "autoprefixer": "^10.4.19",
27
27
  "css-loader": "^7.1.2",
28
28
  "css-minimizer-webpack-plugin": "^7.0.0",
29
- "cssnano": "^7.0.3",
29
+ "cssnano": "^7.0.4",
30
30
  "defu": "^6.1.4",
31
- "esbuild-loader": "^4.2.0",
31
+ "esbuild-loader": "^4.2.2",
32
32
  "escape-string-regexp": "^5.0.0",
33
33
  "estree-walker": "^3.0.3",
34
34
  "file-loader": "^6.2.0",
@@ -51,19 +51,19 @@
51
51
  "pug-plain-loader": "^1.1.0",
52
52
  "std-env": "^3.7.0",
53
53
  "time-fix-plugin": "^2.0.7",
54
- "ufo": "^1.5.3",
55
- "unenv": "^1.9.0",
54
+ "ufo": "^1.5.4",
55
+ "unenv": "^1.10.0",
56
56
  "unplugin": "^1.11.0",
57
57
  "url-loader": "^4.1.1",
58
58
  "vue-bundle-renderer": "^2.1.0",
59
59
  "vue-loader": "^17.4.2",
60
- "webpack": "^5.92.1",
60
+ "webpack": "^5.93.0",
61
61
  "webpack-bundle-analyzer": "^4.10.2",
62
- "webpack-dev-middleware": "^7.2.1",
62
+ "webpack-dev-middleware": "^7.3.0",
63
63
  "webpack-hot-middleware": "^2.26.1",
64
64
  "webpack-virtual-modules": "^0.6.2",
65
65
  "webpackbar": "^6.0.1",
66
- "@nuxt/kit": "3.12.3"
66
+ "@nuxt/kit": "3.12.4"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/hash-sum": "1.0.2",
@@ -72,8 +72,8 @@
72
72
  "@types/webpack-bundle-analyzer": "4.7.0",
73
73
  "@types/webpack-hot-middleware": "2.25.9",
74
74
  "unbuild": "latest",
75
- "vue": "3.4.31",
76
- "@nuxt/schema": "3.12.3"
75
+ "vue": "3.4.32",
76
+ "@nuxt/schema": "3.12.4"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "vue": "^3.3.4"