@nuxt/webpack-builder 3.0.0-rc.2 → 3.0.0-rc.5
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.mjs +88 -18
- package/package.json +25 -24
package/dist/index.mjs
CHANGED
|
@@ -2,12 +2,15 @@ import pify from 'pify';
|
|
|
2
2
|
import webpack from 'webpack';
|
|
3
3
|
import webpackDevMiddleware from 'webpack-dev-middleware';
|
|
4
4
|
import webpackHotMiddleware from 'webpack-hot-middleware';
|
|
5
|
-
import { joinURL } from 'ufo';
|
|
5
|
+
import { parseURL, joinURL } from 'ufo';
|
|
6
6
|
import { useNuxt, logger, requireModule } from '@nuxt/kit';
|
|
7
7
|
import { createUnplugin } from 'unplugin';
|
|
8
|
-
import 'escape-string-regexp';
|
|
8
|
+
import escapeRE from 'escape-string-regexp';
|
|
9
9
|
import MagicString from 'magic-string';
|
|
10
|
-
import {
|
|
10
|
+
import { pathToFileURL } from 'node:url';
|
|
11
|
+
import { isAbsolute, relative, join, resolve, normalize, dirname } from 'pathe';
|
|
12
|
+
import { walk } from 'estree-walker';
|
|
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';
|
|
@@ -21,7 +24,7 @@ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
|
21
24
|
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
22
25
|
import { createCommonJS } from 'mlly';
|
|
23
26
|
import VueLoaderPlugin from 'vue-loader/dist/pluginWebpack5.js';
|
|
24
|
-
import hash from 'hash-sum';
|
|
27
|
+
import hash$1 from 'hash-sum';
|
|
25
28
|
import fse from 'fs-extra';
|
|
26
29
|
import ForkTSCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
|
|
27
30
|
|
|
@@ -56,11 +59,11 @@ const DynamicBasePlugin = createUnplugin(function(options = {}) {
|
|
|
56
59
|
s.prepend("import { publicAssetsURL as __publicAssetsURL } from '#build/paths.mjs';\n");
|
|
57
60
|
}
|
|
58
61
|
if (id === "vite/preload-helper") {
|
|
59
|
-
s.prepend("import {
|
|
60
|
-
s.replace(/const base = ['"]\/__NUXT_BASE__\/['"]/, "const base =
|
|
62
|
+
s.prepend("import { buildAssetsURL } from '#build/paths.mjs';\n");
|
|
63
|
+
s.replace(/const base = ['"]\/__NUXT_BASE__\/['"]/, "const base = buildAssetsURL()");
|
|
61
64
|
}
|
|
62
65
|
s.replace(/from *['"]\/__NUXT_BASE__(\/[^'"]*)['"]/g, 'from "$1"');
|
|
63
|
-
const delimiterRE = /(?<!(const base = |from *))(`([^`]*)\/__NUXT_BASE__\/([^`]*)`|'([^\n']*)\/__NUXT_BASE__\/([^\n']*)'|"([^\n"]*)\/__NUXT_BASE__\/([^\n"]*)")/g;
|
|
66
|
+
const delimiterRE = /(?<!(const base = |from *))((?<!\\)`([^`]*)\/__NUXT_BASE__\/([^`]*)(?<!\\)`|(?<!\\)'([^\n']*)\/__NUXT_BASE__\/([^\n']*)(?<!\\)'|(?<!\\)"([^\n"]*)\/__NUXT_BASE__\/([^\n"]*)(?<!\\)")/g;
|
|
64
67
|
s.replace(delimiterRE, (r) => "`" + r.replace(/\/__NUXT_BASE__\//g, "${__publicAssetsURL()}").slice(1, -1) + "`");
|
|
65
68
|
if (s.hasChanged()) {
|
|
66
69
|
return {
|
|
@@ -72,6 +75,53 @@ const DynamicBasePlugin = createUnplugin(function(options = {}) {
|
|
|
72
75
|
};
|
|
73
76
|
});
|
|
74
77
|
|
|
78
|
+
const keyedFunctions = [
|
|
79
|
+
"useState",
|
|
80
|
+
"useFetch",
|
|
81
|
+
"useAsyncData",
|
|
82
|
+
"useLazyAsyncData",
|
|
83
|
+
"useLazyFetch"
|
|
84
|
+
];
|
|
85
|
+
const KEYED_FUNCTIONS_RE = new RegExp(`(${keyedFunctions.join("|")})`);
|
|
86
|
+
const composableKeysPlugin = createUnplugin((options = {}) => {
|
|
87
|
+
return {
|
|
88
|
+
name: "nuxt:composable-keys",
|
|
89
|
+
enforce: "post",
|
|
90
|
+
transform(code, id) {
|
|
91
|
+
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
92
|
+
if (!pathname.match(/\.(m?[jt]sx?|vue)/)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!KEYED_FUNCTIONS_RE.test(code)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=<script[^>]*>)[\S\s.]*?(?=<\/script>)/) || [];
|
|
99
|
+
const s = new MagicString(code);
|
|
100
|
+
const relativeID = isAbsolute(id) ? relative(options.rootDir, id) : id;
|
|
101
|
+
walk(this.parse(script, {
|
|
102
|
+
sourceType: "module",
|
|
103
|
+
ecmaVersion: "latest"
|
|
104
|
+
}), {
|
|
105
|
+
enter(node) {
|
|
106
|
+
if (node.type !== "CallExpression" || node.callee.type !== "Identifier") {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (keyedFunctions.includes(node.callee.name) && node.arguments.length < 4) {
|
|
110
|
+
const end = node.end;
|
|
111
|
+
s.appendLeft(codeIndex + end - 1, (node.arguments.length ? ", " : "") + "'$" + hash(`${relativeID}-${codeIndex + end}`) + "'");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
if (s.hasChanged()) {
|
|
116
|
+
return {
|
|
117
|
+
code: s.toString(),
|
|
118
|
+
map: options.sourcemap && s.generateMap({ source: id, includeContent: true })
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
|
|
75
125
|
function createMFS() {
|
|
76
126
|
const fs = createFsFromVolume(new Volume());
|
|
77
127
|
const _fs = { ...fs };
|
|
@@ -204,7 +254,8 @@ function base(ctx) {
|
|
|
204
254
|
baseAlias,
|
|
205
255
|
baseConfig,
|
|
206
256
|
basePlugins,
|
|
207
|
-
baseResolve
|
|
257
|
+
baseResolve,
|
|
258
|
+
baseTranspile
|
|
208
259
|
]);
|
|
209
260
|
}
|
|
210
261
|
function baseConfig(ctx) {
|
|
@@ -304,6 +355,25 @@ function baseResolve(ctx) {
|
|
|
304
355
|
...config.resolveLoader
|
|
305
356
|
};
|
|
306
357
|
}
|
|
358
|
+
function baseTranspile(ctx) {
|
|
359
|
+
const { options } = ctx;
|
|
360
|
+
const transpile = [
|
|
361
|
+
/\.vue\.js/i,
|
|
362
|
+
/consola\/src/,
|
|
363
|
+
/vue-demi/
|
|
364
|
+
];
|
|
365
|
+
for (let pattern of options.build.transpile) {
|
|
366
|
+
if (typeof pattern === "function") {
|
|
367
|
+
pattern = pattern(ctx);
|
|
368
|
+
}
|
|
369
|
+
if (typeof pattern === "string") {
|
|
370
|
+
transpile.push(new RegExp(escapeRE(normalize(pattern))));
|
|
371
|
+
} else if (pattern instanceof RegExp) {
|
|
372
|
+
transpile.push(pattern);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
ctx.transpile = [...transpile, ...ctx.transpile];
|
|
376
|
+
}
|
|
307
377
|
function getCache(ctx) {
|
|
308
378
|
const { options } = ctx;
|
|
309
379
|
if (!options.dev) {
|
|
@@ -458,7 +528,7 @@ const getPostcssConfig = (nuxt) => {
|
|
|
458
528
|
if (!nuxt.options.webpack.postcss || !nuxt.options.postcss) {
|
|
459
529
|
return false;
|
|
460
530
|
}
|
|
461
|
-
const configFile = nuxt.options.postcss
|
|
531
|
+
const configFile = nuxt.options.postcss.config;
|
|
462
532
|
if (configFile) {
|
|
463
533
|
return {
|
|
464
534
|
postcssOptions: {
|
|
@@ -505,7 +575,7 @@ function extractCSS(ctx) {
|
|
|
505
575
|
config.plugins.push(new MiniCssExtractPlugin({
|
|
506
576
|
filename: fileName(ctx, "css"),
|
|
507
577
|
chunkFilename: fileName(ctx, "css"),
|
|
508
|
-
...options.webpack.extractCSS
|
|
578
|
+
...options.webpack.extractCSS === true ? {} : options.webpack.extractCSS
|
|
509
579
|
}));
|
|
510
580
|
}
|
|
511
581
|
}
|
|
@@ -562,10 +632,6 @@ function createCssLoadersRule(ctx, cssLoaderOptions) {
|
|
|
562
632
|
];
|
|
563
633
|
}
|
|
564
634
|
return [
|
|
565
|
-
{
|
|
566
|
-
loader: "vue-style-loader",
|
|
567
|
-
options: options.webpack.loaders.vueStyle
|
|
568
|
-
},
|
|
569
635
|
cssLoader
|
|
570
636
|
];
|
|
571
637
|
}
|
|
@@ -612,7 +678,7 @@ class VueSSRClientPlugin {
|
|
|
612
678
|
const asyncFiles = allFiles.filter((file) => isJS(file) || isCSS(file)).filter((file) => !initialFiles.includes(file)).filter((file) => !isHotUpdate(file));
|
|
613
679
|
const assetsMapping = {};
|
|
614
680
|
stats.assets.filter(({ name }) => isJS(name)).filter(({ name }) => !isHotUpdate(name)).forEach(({ name, chunkNames }) => {
|
|
615
|
-
const componentHash = hash(chunkNames.join("|"));
|
|
681
|
+
const componentHash = hash$1(chunkNames.join("|"));
|
|
616
682
|
if (!assetsMapping[componentHash]) {
|
|
617
683
|
assetsMapping[componentHash] = [];
|
|
618
684
|
}
|
|
@@ -649,10 +715,10 @@ class VueSSRClientPlugin {
|
|
|
649
715
|
}
|
|
650
716
|
}
|
|
651
717
|
const files = Array.from(filesSet);
|
|
652
|
-
manifest.modules[hash(id)] = files;
|
|
718
|
+
manifest.modules[hash$1(id)] = files;
|
|
653
719
|
if (Array.isArray(m.modules)) {
|
|
654
720
|
for (const concatenatedModule of m.modules) {
|
|
655
|
-
const id2 = hash(concatenatedModule.identifier.replace(/\s\w+$/, ""));
|
|
721
|
+
const id2 = hash$1(concatenatedModule.identifier.replace(/\s\w+$/, ""));
|
|
656
722
|
if (!manifest.modules[id2]) {
|
|
657
723
|
manifest.modules[id2] = files;
|
|
658
724
|
}
|
|
@@ -942,7 +1008,7 @@ function serverPlugins(ctx) {
|
|
|
942
1008
|
}
|
|
943
1009
|
|
|
944
1010
|
async function bundle(nuxt) {
|
|
945
|
-
|
|
1011
|
+
registerVirtualModules();
|
|
946
1012
|
const webpackConfigs = [client, ...nuxt.options.ssr ? [server] : []].map((preset) => {
|
|
947
1013
|
const ctx = createWebpackConfigContext(nuxt);
|
|
948
1014
|
applyPresets(ctx, preset);
|
|
@@ -955,6 +1021,10 @@ async function bundle(nuxt) {
|
|
|
955
1021
|
sourcemap: nuxt.options.sourcemap,
|
|
956
1022
|
globalPublicPath: "__webpack_public_path__"
|
|
957
1023
|
}));
|
|
1024
|
+
config.plugins.push(composableKeysPlugin.webpack({
|
|
1025
|
+
sourcemap: nuxt.options.sourcemap,
|
|
1026
|
+
rootDir: nuxt.options.rootDir
|
|
1027
|
+
}));
|
|
958
1028
|
const compiler = webpack(config);
|
|
959
1029
|
if (nuxt.options.dev) {
|
|
960
1030
|
compiler.outputFileSystem = mfs;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/webpack-builder",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.5",
|
|
4
4
|
"repository": "nuxt/framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -16,56 +16,57 @@
|
|
|
16
16
|
"prepack": "unbuild"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@babel/core": "^7.
|
|
19
|
+
"@babel/core": "^7.18.6",
|
|
20
20
|
"@nuxt/friendly-errors-webpack-plugin": "^2.5.2",
|
|
21
|
-
"@nuxt/kit": "^3.0.0-rc.
|
|
21
|
+
"@nuxt/kit": "^3.0.0-rc.5",
|
|
22
22
|
"autoprefixer": "^10.4.7",
|
|
23
23
|
"css-loader": "^6.7.1",
|
|
24
|
-
"css-minimizer-webpack-plugin": "^
|
|
25
|
-
"cssnano": "^5.1.
|
|
26
|
-
"esbuild-loader": "^2.
|
|
24
|
+
"css-minimizer-webpack-plugin": "^4.0.0",
|
|
25
|
+
"cssnano": "^5.1.12",
|
|
26
|
+
"esbuild-loader": "^2.19.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.
|
|
30
|
+
"fork-ts-checker-webpack-plugin": "^7.2.12",
|
|
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.
|
|
34
|
-
"memfs": "^3.4.
|
|
35
|
-
"mini-css-extract-plugin": "^2.6.
|
|
36
|
-
"mlly": "^0.5.
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
34
|
+
"magic-string": "^0.26.2",
|
|
35
|
+
"memfs": "^3.4.7",
|
|
36
|
+
"mini-css-extract-plugin": "^2.6.1",
|
|
37
|
+
"mlly": "^0.5.4",
|
|
38
|
+
"ohash": "^0.1.0",
|
|
39
|
+
"pathe": "^0.3.2",
|
|
40
|
+
"pify": "^6.0.0",
|
|
41
|
+
"postcss": "^8.4.14",
|
|
40
42
|
"postcss-import": "^14.1.0",
|
|
41
|
-
"postcss-loader": "^
|
|
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.
|
|
46
|
-
"unplugin": "^0.
|
|
47
|
+
"ufo": "^0.8.5",
|
|
48
|
+
"unplugin": "^0.7.2",
|
|
47
49
|
"url-loader": "^4.1.1",
|
|
48
50
|
"vue-loader": "^17.0.0",
|
|
49
|
-
"
|
|
50
|
-
"webpack": "^5.72.0",
|
|
51
|
+
"webpack": "^5.73.0",
|
|
51
52
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
52
|
-
"webpack-dev-middleware": "^5.3.
|
|
53
|
+
"webpack-dev-middleware": "^5.3.3",
|
|
53
54
|
"webpack-hot-middleware": "^2.25.1",
|
|
54
|
-
"webpack-virtual-modules": "^0.4.
|
|
55
|
+
"webpack-virtual-modules": "^0.4.4",
|
|
55
56
|
"webpackbar": "^5.0.2"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
|
-
"@nuxt/schema": "^3.0.0-rc.
|
|
59
|
+
"@nuxt/schema": "^3.0.0-rc.5",
|
|
59
60
|
"@types/pify": "^5.0.1",
|
|
60
61
|
"@types/webpack-bundle-analyzer": "^4.4.1",
|
|
61
62
|
"@types/webpack-dev-middleware": "^5.0.2",
|
|
62
63
|
"@types/webpack-hot-middleware": "^2.25.6",
|
|
63
64
|
"@types/webpack-virtual-modules": "^0",
|
|
64
65
|
"unbuild": "latest",
|
|
65
|
-
"vue": "3.2.
|
|
66
|
+
"vue": "3.2.37"
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
68
|
-
"vue": "3.2.
|
|
69
|
+
"vue": "^3.2.37"
|
|
69
70
|
},
|
|
70
71
|
"engines": {
|
|
71
72
|
"node": "^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0"
|