@nuxt/webpack-builder 3.1.1 → 3.2.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.
package/README.md CHANGED
@@ -114,7 +114,7 @@ Follow the docs to [Set Up Your Local Development Environment](https://nuxt.com/
114
114
 
115
115
  ## Nuxt 2
116
116
 
117
- You can find the code for Nuxt 2 on the [`2.x-dev` branch](https://github.com/nuxt/nuxt/tree/2.x-dev) and the documentation at [nuxtjs.org](https://nuxtjs.org).
117
+ You can find the code for Nuxt 2 on the [`2.x` branch](https://github.com/nuxt/nuxt/tree/2.x) and the documentation at [nuxtjs.org](https://nuxtjs.org).
118
118
 
119
119
  ## Follow us
120
120
 
package/dist/index.mjs CHANGED
@@ -11,24 +11,24 @@ import { isAbsolute, relative, join, resolve, normalize, dirname } from 'pathe';
11
11
  import { walk } from 'estree-walker';
12
12
  import MagicString from 'magic-string';
13
13
  import { hash } from 'ohash';
14
+ import { findStaticImports, parseStaticImport, createCommonJS } from 'mlly';
14
15
  import { createFsFromVolume, Volume } from 'memfs';
15
16
  import VirtualModulesPlugin from 'webpack-virtual-modules';
16
17
  import querystring from 'node:querystring';
17
18
  import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
19
+ import ForkTSCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
18
20
  import { cloneDeep, defaults as defaults$1, merge, uniq } from 'lodash-es';
19
21
  import TimeFixPlugin from 'time-fix-plugin';
20
22
  import WebpackBar from 'webpackbar';
21
23
  import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin';
22
24
  import escapeRegExp from 'escape-string-regexp';
23
- import esbuildLoader from 'esbuild-loader';
25
+ import { EsbuildPlugin } from 'esbuild-loader';
24
26
  import MiniCssExtractPlugin from 'mini-css-extract-plugin';
25
27
  import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
26
- import { createCommonJS } from 'mlly';
27
28
  import VueLoaderPlugin from 'vue-loader/dist/pluginWebpack5.js';
28
29
  import { normalizeWebpackManifest } from 'vue-bundle-renderer';
29
30
  import hash$1 from 'hash-sum';
30
31
  import fse from 'fs-extra';
31
- import ForkTSCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
32
32
 
33
33
  const keyedFunctions = [
34
34
  "useState",
@@ -53,6 +53,7 @@ const composableKeysPlugin = createUnplugin((options) => {
53
53
  }
54
54
  const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=<script[^>]*>)[\S\s.]*?(?=<\/script>)/) || { index: 0, 0: code };
55
55
  const s = new MagicString(code);
56
+ let imports;
56
57
  let count = 0;
57
58
  const relativeID = isAbsolute(id) ? relative(options.rootDir, id) : id;
58
59
  walk(this.parse(script, {
@@ -68,6 +69,10 @@ const composableKeysPlugin = createUnplugin((options) => {
68
69
  if (!name || !keyedFunctions.includes(name) || node.arguments.length >= 4) {
69
70
  return;
70
71
  }
72
+ imports = imports || detectImportNames(script);
73
+ if (imports.has(name)) {
74
+ return;
75
+ }
71
76
  switch (name) {
72
77
  case "useState":
73
78
  if (node.arguments.length >= 2 || stringTypes.includes(node.arguments[0]?.type)) {
@@ -103,6 +108,27 @@ const composableKeysPlugin = createUnplugin((options) => {
103
108
  }
104
109
  };
105
110
  });
111
+ const NUXT_IMPORT_RE = /nuxt|#app|#imports/;
112
+ function detectImportNames(code) {
113
+ const imports = findStaticImports(code);
114
+ const names = /* @__PURE__ */ new Set();
115
+ for (const i of imports) {
116
+ if (NUXT_IMPORT_RE.test(i.specifier)) {
117
+ continue;
118
+ }
119
+ const { namedImports, defaultImport, namespacedImport } = parseStaticImport(i);
120
+ for (const name in namedImports || {}) {
121
+ names.add(namedImports[name]);
122
+ }
123
+ if (defaultImport) {
124
+ names.add(defaultImport);
125
+ }
126
+ if (namespacedImport) {
127
+ names.add(namespacedImport);
128
+ }
129
+ }
130
+ return names;
131
+ }
106
132
 
107
133
  const defaults = {
108
134
  globalPublicPath: "__webpack_public_path__",
@@ -445,7 +471,7 @@ function getEnv(ctx) {
445
471
  function esbuild(ctx) {
446
472
  const { config } = ctx;
447
473
  const target = ctx.isServer ? "es2019" : "chrome85";
448
- config.optimization.minimizer.push(new esbuildLoader.ESBuildMinifyPlugin());
474
+ config.optimization.minimizer.push(new EsbuildPlugin());
449
475
  config.module.rules.push(
450
476
  {
451
477
  test: /\.m?[jt]s$/i,
@@ -945,6 +971,18 @@ function clientPlugins(ctx) {
945
971
  ...options.webpack.analyze === true ? {} : options.webpack.analyze
946
972
  }));
947
973
  }
974
+ if (!ctx.nuxt.options.ssr) {
975
+ if (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev) {
976
+ config.plugins.push(new ForkTSCheckerWebpackPlugin({
977
+ logger,
978
+ typescript: {
979
+ extensions: {
980
+ vue: { compiler: "@vue/compiler-sfc" }
981
+ }
982
+ }
983
+ }));
984
+ }
985
+ }
948
986
  }
949
987
 
950
988
  function node(ctx) {
@@ -1041,7 +1079,14 @@ function serverPlugins(ctx) {
1041
1079
  }));
1042
1080
  }
1043
1081
  if (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev) {
1044
- config.plugins.push(new ForkTSCheckerWebpackPlugin({ logger }));
1082
+ config.plugins.push(new ForkTSCheckerWebpackPlugin({
1083
+ logger,
1084
+ typescript: {
1085
+ extensions: {
1086
+ vue: { compiler: "@vue/compiler-sfc" }
1087
+ }
1088
+ }
1089
+ }));
1045
1090
  }
1046
1091
  }
1047
1092
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/webpack-builder",
3
- "version": "3.1.1",
3
+ "version": "3.2.0",
4
4
  "repository": "nuxt/nuxt",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,12 +15,12 @@
15
15
  "dependencies": {
16
16
  "@babel/core": "^7.20.12",
17
17
  "@nuxt/friendly-errors-webpack-plugin": "^2.5.2",
18
- "@nuxt/kit": "3.1.1",
18
+ "@nuxt/kit": "3.2.0",
19
19
  "autoprefixer": "^10.4.13",
20
20
  "css-loader": "^6.7.3",
21
21
  "css-minimizer-webpack-plugin": "^4.2.2",
22
22
  "cssnano": "^5.1.14",
23
- "esbuild-loader": "^2.21.0",
23
+ "esbuild-loader": "^3.0.0",
24
24
  "escape-string-regexp": "^5.0.0",
25
25
  "estree-walker": "^3.0.3",
26
26
  "file-loader": "^6.2.0",
@@ -44,7 +44,7 @@
44
44
  "ufo": "^1.0.1",
45
45
  "unplugin": "^1.0.1",
46
46
  "url-loader": "^4.1.1",
47
- "vue-bundle-renderer": "^1.0.0",
47
+ "vue-bundle-renderer": "^1.0.1",
48
48
  "vue-loader": "^17.0.1",
49
49
  "webpack": "^5.75.0",
50
50
  "webpack-bundle-analyzer": "^4.7.0",
@@ -54,7 +54,7 @@
54
54
  "webpackbar": "^5.0.2"
55
55
  },
56
56
  "devDependencies": {
57
- "@nuxt/schema": "3.1.1",
57
+ "@nuxt/schema": "3.2.0",
58
58
  "@types/lodash-es": "^4.17.6",
59
59
  "@types/pify": "^5.0.1",
60
60
  "@types/webpack-bundle-analyzer": "^4.6.0",
@@ -62,10 +62,10 @@
62
62
  "@types/webpack-hot-middleware": "^2.25.6",
63
63
  "@types/webpack-virtual-modules": "^0",
64
64
  "unbuild": "latest",
65
- "vue": "3.2.45"
65
+ "vue": "3.2.47"
66
66
  },
67
67
  "peerDependencies": {
68
- "vue": "^3.2.45"
68
+ "vue": "^3.2.47"
69
69
  },
70
70
  "engines": {
71
71
  "node": "^14.16.0 || ^16.10.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"