@nuxt/webpack-builder 3.12.3 → 3.13.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 +3 -3
  2. package/dist/index.mjs +59 -62
  3. package/package.json +16 -16
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,10 +106,10 @@ 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
- <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>
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>
113
113
  </p>
114
114
 
115
115
  ## <a name="license">⚖️ License</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, resolveAlias, 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,45 @@ 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;
730
+ }
731
+ let pluginPath = resolveAlias(pluginName, nuxt.options.alias);
732
+ let pluginFn;
733
+ if (pluginPath[0] === ".") {
734
+ pluginPath = resolve(nuxt.options.rootDir, pluginPath);
750
735
  }
751
- return pluginFn(pluginOptions);
752
- }).filter(Boolean);
736
+ const path = await tryResolveModule(pluginPath, nuxt.options.modulesDir);
737
+ if (path) {
738
+ pluginFn = await import(pathToFileURL(path).href).then(interopDefault);
739
+ } else {
740
+ if (!isAbsolute(pluginPath)) {
741
+ console.warn(`[nuxt] could not import postcss plugin \`${pluginName}\` with ESM. Please report this as a bug.`);
742
+ }
743
+ pluginFn = requireModule(pluginPath, { paths: [cwd] });
744
+ }
745
+ if (typeof pluginFn === "function") {
746
+ plugins.push(pluginFn(pluginOptions));
747
+ }
748
+ }
749
+ postcssOptions.plugins = plugins;
753
750
  }
754
751
  return {
755
752
  sourceMap: nuxt.options.webpack.cssSourceMap,
756
753
  ...nuxt.options.webpack.postcss,
757
754
  postcssOptions
758
755
  };
759
- };
756
+ }
760
757
 
761
- function style(ctx) {
762
- applyPresets(ctx, [
758
+ async function style(ctx) {
759
+ await applyPresets(ctx, [
763
760
  loaders,
764
761
  extractCSS,
765
762
  minimizer
@@ -784,21 +781,21 @@ function extractCSS(ctx) {
784
781
  ...config === true ? {} : config
785
782
  }));
786
783
  }
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));
784
+ async function loaders(ctx) {
785
+ ctx.config.module.rules.push(await createdStyleRule("css", /\.css$/i, null, ctx));
786
+ ctx.config.module.rules.push(await createdStyleRule("postcss", /\.p(ost)?css$/i, null, ctx));
790
787
  const lessLoader = { loader: "less-loader", options: ctx.userConfig.loaders.less };
791
- ctx.config.module.rules.push(createdStyleRule("less", /\.less$/i, lessLoader, ctx));
788
+ ctx.config.module.rules.push(await createdStyleRule("less", /\.less$/i, lessLoader, ctx));
792
789
  const sassLoader = { loader: "sass-loader", options: ctx.userConfig.loaders.sass };
793
- ctx.config.module.rules.push(createdStyleRule("sass", /\.sass$/i, sassLoader, ctx));
790
+ ctx.config.module.rules.push(await createdStyleRule("sass", /\.sass$/i, sassLoader, ctx));
794
791
  const scssLoader = { loader: "sass-loader", options: ctx.userConfig.loaders.scss };
795
- ctx.config.module.rules.push(createdStyleRule("scss", /\.scss$/i, scssLoader, ctx));
792
+ ctx.config.module.rules.push(await createdStyleRule("scss", /\.scss$/i, scssLoader, ctx));
796
793
  const stylusLoader = { loader: "stylus-loader", options: ctx.userConfig.loaders.stylus };
797
- ctx.config.module.rules.push(createdStyleRule("stylus", /\.styl(us)?$/i, stylusLoader, ctx));
794
+ ctx.config.module.rules.push(await createdStyleRule("stylus", /\.styl(us)?$/i, stylusLoader, ctx));
798
795
  }
799
- function createdStyleRule(lang, test, processorLoader, ctx) {
796
+ async function createdStyleRule(lang, test, processorLoader, ctx) {
800
797
  const styleLoaders = [
801
- createPostcssLoadersRule(ctx),
798
+ await createPostcssLoadersRule(ctx),
802
799
  processorLoader
803
800
  ].filter(Boolean);
804
801
  ctx.userConfig.loaders.css.importLoaders = ctx.userConfig.loaders.cssModules.importLoaders = styleLoaders.length;
@@ -844,11 +841,11 @@ function createCssLoadersRule(ctx, cssLoaderOptions) {
844
841
  cssLoader
845
842
  ];
846
843
  }
847
- function createPostcssLoadersRule(ctx) {
844
+ async function createPostcssLoadersRule(ctx) {
848
845
  if (!ctx.options.postcss) {
849
846
  return;
850
847
  }
851
- const config = getPostcssConfig(ctx.nuxt);
848
+ const config = await getPostcssConfig(ctx.nuxt);
852
849
  if (!config) {
853
850
  return;
854
851
  }
@@ -1076,8 +1073,8 @@ function vue(ctx) {
1076
1073
  }));
1077
1074
  }
1078
1075
 
1079
- function nuxt(ctx) {
1080
- applyPresets(ctx, [
1076
+ async function nuxt(ctx) {
1077
+ await applyPresets(ctx, [
1081
1078
  base,
1082
1079
  assets,
1083
1080
  esbuild,
@@ -1087,10 +1084,10 @@ function nuxt(ctx) {
1087
1084
  ]);
1088
1085
  }
1089
1086
 
1090
- function client(ctx) {
1087
+ async function client(ctx) {
1091
1088
  ctx.name = "client";
1092
1089
  ctx.isClient = true;
1093
- applyPresets(ctx, [
1090
+ await applyPresets(ctx, [
1094
1091
  nuxt,
1095
1092
  clientPlugins,
1096
1093
  clientOptimization,
@@ -1212,10 +1209,10 @@ function node(ctx) {
1212
1209
  }
1213
1210
 
1214
1211
  const assetPattern = /\.(?:css|s[ca]ss|png|jpe?g|gif|svg|woff2?|eot|ttf|otf|webp|webm|mp4|ogv)(?:\?.*)?$/i;
1215
- function server(ctx) {
1212
+ async function server(ctx) {
1216
1213
  ctx.name = "server";
1217
1214
  ctx.isServer = true;
1218
- applyPresets(ctx, [
1215
+ await applyPresets(ctx, [
1219
1216
  nuxt,
1220
1217
  node,
1221
1218
  serverStandalone,
@@ -1287,12 +1284,12 @@ function serverPlugins(ctx) {
1287
1284
 
1288
1285
  const bundle = async (nuxt) => {
1289
1286
  registerVirtualModules();
1290
- const webpackConfigs = [client, ...nuxt.options.ssr ? [server] : []].map((preset) => {
1287
+ const webpackConfigs = await Promise.all([client, ...nuxt.options.ssr ? [server] : []].map(async (preset) => {
1291
1288
  const ctx = createWebpackConfigContext(nuxt);
1292
1289
  ctx.userConfig = defu(nuxt.options.webpack[`$${preset.name}`], ctx.userConfig);
1293
- applyPresets(ctx, preset);
1290
+ await applyPresets(ctx, preset);
1294
1291
  return getWebpackConfig(ctx);
1295
- });
1292
+ }));
1296
1293
  await nuxt.callHook("webpack:config", webpackConfigs);
1297
1294
  const mfs = nuxt.options.dev ? createMFS() : null;
1298
1295
  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.13.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -23,12 +23,12 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "@nuxt/friendly-errors-webpack-plugin": "^2.6.0",
26
- "autoprefixer": "^10.4.19",
26
+ "autoprefixer": "^10.4.20",
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.5",
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",
@@ -36,14 +36,14 @@
36
36
  "h3": "^1.12.0",
37
37
  "hash-sum": "^2.0.0",
38
38
  "lodash-es": "4.17.21",
39
- "magic-string": "^0.30.10",
40
- "memfs": "^4.9.3",
41
- "mini-css-extract-plugin": "^2.9.0",
39
+ "magic-string": "^0.30.11",
40
+ "memfs": "^4.11.1",
41
+ "mini-css-extract-plugin": "^2.9.1",
42
42
  "mlly": "^1.7.1",
43
43
  "ohash": "^1.1.3",
44
44
  "pathe": "^1.1.2",
45
45
  "pify": "^6.1.0",
46
- "postcss": "^8.4.39",
46
+ "postcss": "^8.4.41",
47
47
  "postcss-import": "^16.1.0",
48
48
  "postcss-import-resolver": "^2.0.0",
49
49
  "postcss-loader": "^8.1.1",
@@ -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",
56
- "unplugin": "^1.11.0",
54
+ "ufo": "^1.5.4",
55
+ "unenv": "^1.10.0",
56
+ "unplugin": "^1.12.2",
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.94.0",
61
61
  "webpack-bundle-analyzer": "^4.10.2",
62
- "webpack-dev-middleware": "^7.2.1",
62
+ "webpack-dev-middleware": "^7.4.2",
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.13.0"
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.38",
76
+ "@nuxt/schema": "3.13.0"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "vue": "^3.3.4"