@nuxt/webpack-builder 3.0.0-rc.8 → 3.0.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/LICENSE +21 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +96 -79
- package/package.json +33 -34
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 - Nuxt Project
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import pify from 'pify';
|
|
2
2
|
import webpack from 'webpack';
|
|
3
|
+
import { fromNodeMiddleware, defineEventHandler } from 'h3';
|
|
3
4
|
import webpackDevMiddleware from 'webpack-dev-middleware';
|
|
4
5
|
import webpackHotMiddleware from 'webpack-hot-middleware';
|
|
5
|
-
import { parseURL, joinURL } from 'ufo';
|
|
6
|
+
import { parseURL, parseQuery, joinURL } from 'ufo';
|
|
6
7
|
import { useNuxt, logger, requireModule } from '@nuxt/kit';
|
|
7
8
|
import { pathToFileURL } from 'node:url';
|
|
8
9
|
import { createUnplugin } from 'unplugin';
|
|
@@ -37,19 +38,20 @@ const keyedFunctions = [
|
|
|
37
38
|
"useLazyFetch"
|
|
38
39
|
];
|
|
39
40
|
const KEYED_FUNCTIONS_RE = new RegExp(`(${keyedFunctions.join("|")})`);
|
|
40
|
-
const
|
|
41
|
+
const stringTypes = ["Literal", "TemplateLiteral"];
|
|
42
|
+
const composableKeysPlugin = createUnplugin((options) => {
|
|
41
43
|
return {
|
|
42
44
|
name: "nuxt:composable-keys",
|
|
43
45
|
enforce: "post",
|
|
46
|
+
transformInclude(id) {
|
|
47
|
+
const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
48
|
+
return !pathname.match(/node_modules\/nuxt3?\//) && pathname.match(/\.(m?[jt]sx?|vue)/) && parseQuery(search).type !== "style" && !parseQuery(search).macro;
|
|
49
|
+
},
|
|
44
50
|
transform(code, id) {
|
|
45
|
-
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
46
|
-
if (!pathname.match(/\.(m?[jt]sx?|vue)/)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
51
|
if (!KEYED_FUNCTIONS_RE.test(code)) {
|
|
50
52
|
return;
|
|
51
53
|
}
|
|
52
|
-
const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=<script[^>]*>)[\S\s.]*?(?=<\/script>)/) ||
|
|
54
|
+
const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=<script[^>]*>)[\S\s.]*?(?=<\/script>)/) || { index: 0, 0: code };
|
|
53
55
|
const s = new MagicString(code);
|
|
54
56
|
let count = 0;
|
|
55
57
|
const relativeID = isAbsolute(id) ? relative(options.rootDir, id) : id;
|
|
@@ -57,23 +59,45 @@ const composableKeysPlugin = createUnplugin((options = {}) => {
|
|
|
57
59
|
sourceType: "module",
|
|
58
60
|
ecmaVersion: "latest"
|
|
59
61
|
}), {
|
|
60
|
-
enter(
|
|
61
|
-
if (
|
|
62
|
+
enter(_node) {
|
|
63
|
+
if (_node.type !== "CallExpression" || _node.callee.type !== "Identifier") {
|
|
62
64
|
return;
|
|
63
65
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
const node = _node;
|
|
67
|
+
const name = "name" in node.callee && node.callee.name;
|
|
68
|
+
if (!name || !keyedFunctions.includes(name) || node.arguments.length >= 4) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
switch (name) {
|
|
72
|
+
case "useState":
|
|
73
|
+
if (node.arguments.length >= 2 || stringTypes.includes(node.arguments[0]?.type)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
case "useFetch":
|
|
78
|
+
case "useLazyFetch":
|
|
79
|
+
if (node.arguments.length >= 3 || stringTypes.includes(node.arguments[1]?.type)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
case "useAsyncData":
|
|
84
|
+
case "useLazyAsyncData":
|
|
85
|
+
if (node.arguments.length >= 3 || stringTypes.includes(node.arguments[0]?.type) || stringTypes.includes(node.arguments[node.arguments.length - 1]?.type)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
70
89
|
}
|
|
90
|
+
const endsWithComma = code.slice(codeIndex + node.start, codeIndex + node.end - 1).trim().endsWith(",");
|
|
91
|
+
s.appendLeft(
|
|
92
|
+
codeIndex + node.end - 1,
|
|
93
|
+
(node.arguments.length && !endsWithComma ? ", " : "") + "'$" + hash(`${relativeID}-${++count}`) + "'"
|
|
94
|
+
);
|
|
71
95
|
}
|
|
72
96
|
});
|
|
73
97
|
if (s.hasChanged()) {
|
|
74
98
|
return {
|
|
75
99
|
code: s.toString(),
|
|
76
|
-
map: options.sourcemap
|
|
100
|
+
map: options.sourcemap ? s.generateMap({ source: id, includeContent: true }) : void 0
|
|
77
101
|
};
|
|
78
102
|
}
|
|
79
103
|
}
|
|
@@ -94,11 +118,12 @@ const DynamicBasePlugin = createUnplugin((options = {}) => {
|
|
|
94
118
|
return;
|
|
95
119
|
}
|
|
96
120
|
const s = new MagicString(code);
|
|
97
|
-
s.append(
|
|
121
|
+
s.append(`
|
|
122
|
+
${options.globalPublicPath} = buildAssetsURL();
|
|
98
123
|
`);
|
|
99
124
|
return {
|
|
100
125
|
code: s.toString(),
|
|
101
|
-
map: options.sourcemap
|
|
126
|
+
map: options.sourcemap ? s.generateMap({ source: id, includeContent: true }) : void 0
|
|
102
127
|
};
|
|
103
128
|
}
|
|
104
129
|
};
|
|
@@ -121,7 +146,7 @@ function registerVirtualModules() {
|
|
|
121
146
|
virtualModules.writeModule(filePath, nuxt.vfs[filePath]);
|
|
122
147
|
}
|
|
123
148
|
};
|
|
124
|
-
nuxt.hook("
|
|
149
|
+
nuxt.hook("webpack:compile", ({ compiler }) => {
|
|
125
150
|
if (compiler.name === "server") {
|
|
126
151
|
writeFiles();
|
|
127
152
|
}
|
|
@@ -270,14 +295,15 @@ function baseConfig(ctx) {
|
|
|
270
295
|
}
|
|
271
296
|
function basePlugins(ctx) {
|
|
272
297
|
const { config, options, nuxt } = ctx;
|
|
298
|
+
config.plugins = config.plugins || [];
|
|
273
299
|
if (options.dev) {
|
|
274
300
|
config.plugins.push(new TimeFixPlugin());
|
|
275
301
|
}
|
|
276
302
|
config.plugins.push(...options.webpack.plugins || []);
|
|
277
303
|
config.plugins.push(new WarningIgnorePlugin(getWarningIgnoreFilter(ctx)));
|
|
278
304
|
config.plugins.push(new webpack.DefinePlugin(getEnv(ctx)));
|
|
279
|
-
if (ctx.isServer || ctx.isDev &&
|
|
280
|
-
|
|
305
|
+
if (ctx.isServer || ctx.isDev && options.webpack.friendlyErrors) {
|
|
306
|
+
config.plugins.push(
|
|
281
307
|
new FriendlyErrorsWebpackPlugin({
|
|
282
308
|
clearConsole: false,
|
|
283
309
|
reporter: "consola",
|
|
@@ -299,21 +325,21 @@ function basePlugins(ctx) {
|
|
|
299
325
|
reporter: {
|
|
300
326
|
change: (_, { shortPath }) => {
|
|
301
327
|
if (!ctx.isServer) {
|
|
302
|
-
nuxt.callHook("
|
|
328
|
+
nuxt.callHook("webpack:change", shortPath);
|
|
303
329
|
}
|
|
304
330
|
},
|
|
305
331
|
done: ({ state }) => {
|
|
306
332
|
if (state.hasErrors) {
|
|
307
|
-
nuxt.callHook("
|
|
333
|
+
nuxt.callHook("webpack:error");
|
|
308
334
|
} else {
|
|
309
335
|
logger.success(`${state.name} ${state.message}`);
|
|
310
336
|
}
|
|
311
337
|
},
|
|
312
338
|
allDone: () => {
|
|
313
|
-
nuxt.callHook("
|
|
339
|
+
nuxt.callHook("webpack:done");
|
|
314
340
|
},
|
|
315
341
|
progress({ statesArray }) {
|
|
316
|
-
nuxt.callHook("
|
|
342
|
+
nuxt.callHook("webpack:progress", statesArray);
|
|
317
343
|
}
|
|
318
344
|
}
|
|
319
345
|
}));
|
|
@@ -395,8 +421,6 @@ function getEnv(ctx) {
|
|
|
395
421
|
"process.env.NODE_ENV": JSON.stringify(ctx.config.mode),
|
|
396
422
|
"process.mode": JSON.stringify(ctx.config.mode),
|
|
397
423
|
"process.dev": options.dev,
|
|
398
|
-
"process.static": options.target === "static",
|
|
399
|
-
"process.target": JSON.stringify(options.target),
|
|
400
424
|
"process.env.VUE_ENV": JSON.stringify(ctx.name),
|
|
401
425
|
"process.browser": ctx.isClient,
|
|
402
426
|
"process.client": ctx.isClient,
|
|
@@ -406,10 +430,6 @@ function getEnv(ctx) {
|
|
|
406
430
|
_env["typeof process"] = JSON.stringify(ctx.isServer ? "object" : "undefined");
|
|
407
431
|
_env["typeof window"] = _env["typeof document"] = JSON.stringify(!ctx.isServer ? "object" : "undefined");
|
|
408
432
|
}
|
|
409
|
-
Object.entries(options.env).forEach(([key, value]) => {
|
|
410
|
-
const isNative = ["boolean", "number"].includes(typeof value);
|
|
411
|
-
_env["process.env." + key] = isNative ? value : JSON.stringify(value);
|
|
412
|
-
});
|
|
413
433
|
return _env;
|
|
414
434
|
}
|
|
415
435
|
|
|
@@ -657,12 +677,12 @@ const validate = (compiler) => {
|
|
|
657
677
|
};
|
|
658
678
|
const isJSRegExp = /\.[cm]?js(\?[^.]+)?$/;
|
|
659
679
|
const isJS = (file) => isJSRegExp.test(file);
|
|
660
|
-
const extractQueryPartJS = (file) => isJSRegExp.exec(file)[1];
|
|
680
|
+
const extractQueryPartJS = (file) => isJSRegExp.exec(file)?.[1];
|
|
661
681
|
const isCSS = (file) => /\.css(\?[^.]+)?$/.test(file);
|
|
662
682
|
const isHotUpdate = (file) => file.includes("hot-update");
|
|
663
683
|
|
|
664
684
|
class VueSSRClientPlugin {
|
|
665
|
-
constructor(options
|
|
685
|
+
constructor(options) {
|
|
666
686
|
this.options = Object.assign({
|
|
667
687
|
filename: null
|
|
668
688
|
}, options);
|
|
@@ -674,14 +694,14 @@ class VueSSRClientPlugin {
|
|
|
674
694
|
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));
|
|
675
695
|
const asyncFiles = allFiles.filter((file) => isJS(file) || isCSS(file)).filter((file) => !initialFiles.includes(file)).filter((file) => !isHotUpdate(file));
|
|
676
696
|
const assetsMapping = {};
|
|
677
|
-
stats.assets.filter(({ name }) => isJS(name)).filter(({ name }) => !isHotUpdate(name)).forEach(({ name, chunkNames }) => {
|
|
697
|
+
stats.assets.filter(({ name }) => isJS(name)).filter(({ name }) => !isHotUpdate(name)).forEach(({ name, chunkNames = [] }) => {
|
|
678
698
|
const componentHash = hash$1(chunkNames.join("|"));
|
|
679
699
|
if (!assetsMapping[componentHash]) {
|
|
680
700
|
assetsMapping[componentHash] = [];
|
|
681
701
|
}
|
|
682
702
|
assetsMapping[componentHash].push(name);
|
|
683
703
|
});
|
|
684
|
-
const
|
|
704
|
+
const webpackManifest = {
|
|
685
705
|
publicPath: stats.publicPath,
|
|
686
706
|
all: allFiles,
|
|
687
707
|
initial: initialFiles,
|
|
@@ -689,9 +709,9 @@ class VueSSRClientPlugin {
|
|
|
689
709
|
modules: {},
|
|
690
710
|
assetsMapping
|
|
691
711
|
};
|
|
692
|
-
const { entrypoints, namedChunkGroups } = stats;
|
|
712
|
+
const { entrypoints = {}, namedChunkGroups = {} } = stats;
|
|
693
713
|
const assetModules = stats.modules.filter((m) => m.assets.length);
|
|
694
|
-
const fileToIndex = (file) =>
|
|
714
|
+
const fileToIndex = (file) => webpackManifest.all.indexOf(file);
|
|
695
715
|
stats.modules.forEach((m) => {
|
|
696
716
|
if (m.chunks.length === 1) {
|
|
697
717
|
const [cid] = m.chunks;
|
|
@@ -712,12 +732,12 @@ class VueSSRClientPlugin {
|
|
|
712
732
|
}
|
|
713
733
|
}
|
|
714
734
|
const files = Array.from(filesSet);
|
|
715
|
-
|
|
735
|
+
webpackManifest.modules[hash$1(id)] = files;
|
|
716
736
|
if (Array.isArray(m.modules)) {
|
|
717
737
|
for (const concatenatedModule of m.modules) {
|
|
718
738
|
const id2 = hash$1(concatenatedModule.identifier.replace(/\s\w+$/, ""));
|
|
719
|
-
if (!
|
|
720
|
-
|
|
739
|
+
if (!webpackManifest.modules[id2]) {
|
|
740
|
+
webpackManifest.modules[id2] = files;
|
|
721
741
|
}
|
|
722
742
|
}
|
|
723
743
|
}
|
|
@@ -728,7 +748,9 @@ class VueSSRClientPlugin {
|
|
|
728
748
|
});
|
|
729
749
|
}
|
|
730
750
|
});
|
|
731
|
-
const
|
|
751
|
+
const manifest = normalizeWebpackManifest(webpackManifest);
|
|
752
|
+
await this.options.nuxt.callHook("build:manifest", manifest);
|
|
753
|
+
const src = JSON.stringify(manifest, null, 2);
|
|
732
754
|
await fse.mkdirp(dirname(this.options.filename));
|
|
733
755
|
await fse.writeFile(this.options.filename, src);
|
|
734
756
|
const mjsSrc = "export default " + src;
|
|
@@ -817,7 +839,8 @@ function vue(ctx) {
|
|
|
817
839
|
});
|
|
818
840
|
if (ctx.isClient) {
|
|
819
841
|
config.plugins.push(new VueSSRClientPlugin({
|
|
820
|
-
filename: resolve(options.buildDir, "dist/server", `${ctx.name}.manifest.json`)
|
|
842
|
+
filename: resolve(options.buildDir, "dist/server", `${ctx.name}.manifest.json`),
|
|
843
|
+
nuxt: ctx.nuxt
|
|
821
844
|
}));
|
|
822
845
|
} else {
|
|
823
846
|
config.plugins.push(new VueSSRServerPlugin({
|
|
@@ -854,13 +877,15 @@ function client(ctx) {
|
|
|
854
877
|
]);
|
|
855
878
|
}
|
|
856
879
|
function clientDevtool(ctx) {
|
|
857
|
-
if (!ctx.
|
|
880
|
+
if (!ctx.nuxt.options.sourcemap.client) {
|
|
858
881
|
ctx.config.devtool = false;
|
|
859
882
|
return;
|
|
860
883
|
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
884
|
+
if (!ctx.isDev) {
|
|
885
|
+
ctx.config.devtool = "source-map";
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
ctx.config.devtool = "eval-cheap-module-source-map";
|
|
864
889
|
}
|
|
865
890
|
function clientPerformance(ctx) {
|
|
866
891
|
ctx.config.performance = {
|
|
@@ -889,6 +914,7 @@ function clientHMR(ctx) {
|
|
|
889
914
|
app.unshift(
|
|
890
915
|
`webpack-hot-middleware/client?${hotMiddlewareClientOptionsStr}`
|
|
891
916
|
);
|
|
917
|
+
config.plugins = config.plugins || [];
|
|
892
918
|
config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
893
919
|
}
|
|
894
920
|
function clientOptimization(_ctx) {
|
|
@@ -901,20 +927,13 @@ function clientPlugins(ctx) {
|
|
|
901
927
|
analyzerMode: "static",
|
|
902
928
|
defaultSizes: "gzip",
|
|
903
929
|
generateStatsFile: true,
|
|
904
|
-
openAnalyzer:
|
|
930
|
+
openAnalyzer: true,
|
|
905
931
|
reportFilename: resolve(statsDir, `${ctx.name}.html`),
|
|
906
932
|
statsFilename: resolve(statsDir, `${ctx.name}.json`),
|
|
907
933
|
...options.webpack.analyze === true ? {} : options.webpack.analyze
|
|
908
934
|
}));
|
|
909
935
|
}
|
|
910
936
|
}
|
|
911
|
-
function getCspScriptPolicy(ctx) {
|
|
912
|
-
const { csp } = ctx.options.render;
|
|
913
|
-
if (typeof csp === "object") {
|
|
914
|
-
const { policies = {} } = csp;
|
|
915
|
-
return policies["script-src"] || policies["default-src"] || [];
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
937
|
|
|
919
938
|
function node(ctx) {
|
|
920
939
|
const { config } = ctx;
|
|
@@ -964,7 +983,7 @@ function server(ctx) {
|
|
|
964
983
|
function serverPreset(ctx) {
|
|
965
984
|
const { config } = ctx;
|
|
966
985
|
config.output.filename = "server.mjs";
|
|
967
|
-
config.devtool = "cheap-module-source-map";
|
|
986
|
+
config.devtool = ctx.nuxt.options.sourcemap.server ? ctx.isDev ? "cheap-module-source-map" : "source-map" : false;
|
|
968
987
|
config.optimization = {
|
|
969
988
|
splitChunks: false,
|
|
970
989
|
minimize: false
|
|
@@ -988,17 +1007,21 @@ function serverStandalone(ctx) {
|
|
|
988
1007
|
return;
|
|
989
1008
|
}
|
|
990
1009
|
ctx.config.externals.push(({ request }, cb) => {
|
|
1010
|
+
if (!request) {
|
|
1011
|
+
return cb(void 0, false);
|
|
1012
|
+
}
|
|
991
1013
|
if (external.includes(request)) {
|
|
992
|
-
return cb(
|
|
1014
|
+
return cb(void 0, true);
|
|
993
1015
|
}
|
|
994
1016
|
if (request[0] === "." || isAbsolute(request) || inline.find((prefix) => typeof prefix === "string" && request.startsWith(prefix)) || assetPattern.test(request)) {
|
|
995
|
-
return cb(
|
|
1017
|
+
return cb(void 0, false);
|
|
996
1018
|
}
|
|
997
|
-
return cb(
|
|
1019
|
+
return cb(void 0, true);
|
|
998
1020
|
});
|
|
999
1021
|
}
|
|
1000
1022
|
function serverPlugins(ctx) {
|
|
1001
1023
|
const { config, options } = ctx;
|
|
1024
|
+
config.plugins = config.plugins || [];
|
|
1002
1025
|
if (options.webpack.serverURLPolyfill) {
|
|
1003
1026
|
config.plugins.push(new webpack.ProvidePlugin({
|
|
1004
1027
|
URL: [options.webpack.serverURLPolyfill, "URL"],
|
|
@@ -1006,7 +1029,7 @@ function serverPlugins(ctx) {
|
|
|
1006
1029
|
}));
|
|
1007
1030
|
}
|
|
1008
1031
|
if (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev) {
|
|
1009
|
-
|
|
1032
|
+
config.plugins.push(new ForkTSCheckerWebpackPlugin({ logger }));
|
|
1010
1033
|
}
|
|
1011
1034
|
}
|
|
1012
1035
|
|
|
@@ -1021,10 +1044,10 @@ async function bundle(nuxt) {
|
|
|
1021
1044
|
const mfs = nuxt.options.dev ? createMFS() : null;
|
|
1022
1045
|
const compilers = webpackConfigs.map((config) => {
|
|
1023
1046
|
config.plugins.push(DynamicBasePlugin.webpack({
|
|
1024
|
-
sourcemap: nuxt.options.sourcemap
|
|
1047
|
+
sourcemap: nuxt.options.sourcemap[config.name]
|
|
1025
1048
|
}));
|
|
1026
1049
|
config.plugins.push(composableKeysPlugin.webpack({
|
|
1027
|
-
sourcemap: nuxt.options.sourcemap,
|
|
1050
|
+
sourcemap: nuxt.options.sourcemap[config.name],
|
|
1028
1051
|
rootDir: nuxt.options.rootDir
|
|
1029
1052
|
}));
|
|
1030
1053
|
const compiler = webpack(config);
|
|
@@ -1048,37 +1071,34 @@ async function bundle(nuxt) {
|
|
|
1048
1071
|
async function createDevMiddleware(compiler) {
|
|
1049
1072
|
const nuxt = useNuxt();
|
|
1050
1073
|
logger.debug("Creating webpack middleware...");
|
|
1051
|
-
const devMiddleware =
|
|
1074
|
+
const devMiddleware = webpackDevMiddleware(compiler, {
|
|
1052
1075
|
publicPath: joinURL(nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir),
|
|
1053
1076
|
outputFileSystem: compiler.outputFileSystem,
|
|
1054
1077
|
stats: "none",
|
|
1055
1078
|
...nuxt.options.webpack.devMiddleware
|
|
1056
|
-
})
|
|
1079
|
+
});
|
|
1057
1080
|
nuxt.hook("close", () => pify(devMiddleware.close.bind(devMiddleware))());
|
|
1058
1081
|
const { client: _client, ...hotMiddlewareOptions } = nuxt.options.webpack.hotMiddleware || {};
|
|
1059
|
-
const hotMiddleware =
|
|
1082
|
+
const hotMiddleware = webpackHotMiddleware(compiler, {
|
|
1060
1083
|
log: false,
|
|
1061
1084
|
heartbeat: 1e4,
|
|
1062
1085
|
path: joinURL(nuxt.options.app.baseURL, "__webpack_hmr", compiler.options.name),
|
|
1063
1086
|
...hotMiddlewareOptions
|
|
1064
|
-
}));
|
|
1065
|
-
await nuxt.callHook("webpack:devMiddleware", devMiddleware);
|
|
1066
|
-
await nuxt.callHook("webpack:hotMiddleware", hotMiddleware);
|
|
1067
|
-
await nuxt.callHook("server:devMiddleware", async (req, res, next) => {
|
|
1068
|
-
for (const mw of [devMiddleware, hotMiddleware]) {
|
|
1069
|
-
await mw?.(req, res);
|
|
1070
|
-
}
|
|
1071
|
-
next();
|
|
1072
1087
|
});
|
|
1088
|
+
const devHandler = fromNodeMiddleware(devMiddleware);
|
|
1089
|
+
const hotHandler = fromNodeMiddleware(hotMiddleware);
|
|
1090
|
+
await nuxt.callHook("server:devHandler", defineEventHandler(async (event) => {
|
|
1091
|
+
await devHandler(event);
|
|
1092
|
+
await hotHandler(event);
|
|
1093
|
+
}));
|
|
1073
1094
|
return devMiddleware;
|
|
1074
1095
|
}
|
|
1075
1096
|
async function compile(compiler) {
|
|
1076
1097
|
const nuxt = useNuxt();
|
|
1077
1098
|
const { name } = compiler.options;
|
|
1078
|
-
await nuxt.callHook("
|
|
1099
|
+
await nuxt.callHook("webpack:compile", { name, compiler });
|
|
1079
1100
|
compiler.hooks.done.tap("load-resources", async (stats2) => {
|
|
1080
|
-
await nuxt.callHook("
|
|
1081
|
-
await nuxt.callHook("build:resources", compiler.outputFileSystem);
|
|
1101
|
+
await nuxt.callHook("webpack:compiled", { name, compiler, stats: stats2 });
|
|
1082
1102
|
});
|
|
1083
1103
|
if (nuxt.options.dev) {
|
|
1084
1104
|
const compilersWatching = [];
|
|
@@ -1111,12 +1131,9 @@ async function compile(compiler) {
|
|
|
1111
1131
|
const stats = await new Promise((resolve, reject) => compiler.run((err, stats2) => err ? reject(err) : resolve(stats2)));
|
|
1112
1132
|
if (stats.hasErrors()) {
|
|
1113
1133
|
const error = new Error("Nuxt build error");
|
|
1114
|
-
|
|
1115
|
-
error.stack = stats.toString("errors-only");
|
|
1116
|
-
}
|
|
1134
|
+
error.stack = stats.toString("errors-only");
|
|
1117
1135
|
throw error;
|
|
1118
1136
|
}
|
|
1119
|
-
await nuxt.callHook("build:resources");
|
|
1120
1137
|
}
|
|
1121
1138
|
|
|
1122
1139
|
export { bundle };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/webpack-builder",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"repository": "nuxt/framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -12,18 +12,15 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
|
-
"scripts": {
|
|
16
|
-
"prepack": "unbuild"
|
|
17
|
-
},
|
|
18
15
|
"dependencies": {
|
|
19
|
-
"@babel/core": "^7.
|
|
16
|
+
"@babel/core": "^7.20.2",
|
|
20
17
|
"@nuxt/friendly-errors-webpack-plugin": "^2.5.2",
|
|
21
|
-
"@nuxt/kit": "3.0.0
|
|
22
|
-
"autoprefixer": "^10.4.
|
|
23
|
-
"css-loader": "^6.7.
|
|
24
|
-
"css-minimizer-webpack-plugin": "^4.
|
|
25
|
-
"cssnano": "^5.1.
|
|
26
|
-
"esbuild-loader": "^2.
|
|
18
|
+
"@nuxt/kit": "3.0.0",
|
|
19
|
+
"autoprefixer": "^10.4.13",
|
|
20
|
+
"css-loader": "^6.7.2",
|
|
21
|
+
"css-minimizer-webpack-plugin": "^4.2.2",
|
|
22
|
+
"cssnano": "^5.1.14",
|
|
23
|
+
"esbuild-loader": "^2.20.0",
|
|
27
24
|
"escape-string-regexp": "^5.0.0",
|
|
28
25
|
"estree-walker": "^3.0.1",
|
|
29
26
|
"file-loader": "^6.2.0",
|
|
@@ -31,45 +28,47 @@
|
|
|
31
28
|
"fs-extra": "^10.1.0",
|
|
32
29
|
"hash-sum": "^2.0.0",
|
|
33
30
|
"lodash-es": "^4.17.21",
|
|
34
|
-
"magic-string": "^0.26.
|
|
35
|
-
"memfs": "^3.4.
|
|
31
|
+
"magic-string": "^0.26.7",
|
|
32
|
+
"memfs": "^3.4.11",
|
|
36
33
|
"mini-css-extract-plugin": "^2.6.1",
|
|
37
|
-
"mlly": "^0.
|
|
38
|
-
"ohash": "^0.
|
|
39
|
-
"pathe": "^0.
|
|
40
|
-
"pify": "^6.
|
|
41
|
-
"postcss": "^8.4.
|
|
42
|
-
"postcss-import": "^
|
|
34
|
+
"mlly": "^1.0.0",
|
|
35
|
+
"ohash": "^1.0.0",
|
|
36
|
+
"pathe": "^1.0.0",
|
|
37
|
+
"pify": "^6.1.0",
|
|
38
|
+
"postcss": "^8.4.19",
|
|
39
|
+
"postcss-import": "^15.0.0",
|
|
43
40
|
"postcss-loader": "^7.0.1",
|
|
44
41
|
"postcss-url": "^10.1.3",
|
|
45
42
|
"style-resources-loader": "^1.5.0",
|
|
46
43
|
"time-fix-plugin": "^2.0.7",
|
|
47
|
-
"ufo": "^0.
|
|
48
|
-
"unplugin": "^0.
|
|
44
|
+
"ufo": "^1.0.0",
|
|
45
|
+
"unplugin": "^1.0.0",
|
|
49
46
|
"url-loader": "^4.1.1",
|
|
50
|
-
"vue-bundle-renderer": "^0.
|
|
51
|
-
"vue-loader": "^17.0.
|
|
52
|
-
"webpack": "^5.
|
|
53
|
-
"webpack-bundle-analyzer": "^4.
|
|
47
|
+
"vue-bundle-renderer": "^1.0.0",
|
|
48
|
+
"vue-loader": "^17.0.1",
|
|
49
|
+
"webpack": "^5.75.0",
|
|
50
|
+
"webpack-bundle-analyzer": "^4.7.0",
|
|
54
51
|
"webpack-dev-middleware": "^5.3.3",
|
|
55
|
-
"webpack-hot-middleware": "^2.25.
|
|
56
|
-
"webpack-virtual-modules": "^0.4.
|
|
52
|
+
"webpack-hot-middleware": "^2.25.3",
|
|
53
|
+
"webpack-virtual-modules": "^0.4.6",
|
|
57
54
|
"webpackbar": "^5.0.2"
|
|
58
55
|
},
|
|
59
56
|
"devDependencies": {
|
|
60
|
-
"@nuxt/schema": "3.0.0
|
|
57
|
+
"@nuxt/schema": "3.0.0",
|
|
58
|
+
"@types/lodash-es": "^4.17.6",
|
|
61
59
|
"@types/pify": "^5.0.1",
|
|
62
|
-
"@types/webpack-bundle-analyzer": "^4.
|
|
60
|
+
"@types/webpack-bundle-analyzer": "^4.6.0",
|
|
63
61
|
"@types/webpack-dev-middleware": "^5.0.2",
|
|
64
62
|
"@types/webpack-hot-middleware": "^2.25.6",
|
|
65
63
|
"@types/webpack-virtual-modules": "^0",
|
|
66
64
|
"unbuild": "latest",
|
|
67
|
-
"vue": "3.2.
|
|
65
|
+
"vue": "3.2.45"
|
|
68
66
|
},
|
|
69
67
|
"peerDependencies": {
|
|
70
|
-
"vue": "^3.2.
|
|
68
|
+
"vue": "^3.2.45"
|
|
71
69
|
},
|
|
72
70
|
"engines": {
|
|
73
|
-
"node": "^14.16.0 || ^16.
|
|
74
|
-
}
|
|
75
|
-
}
|
|
71
|
+
"node": "^14.16.0 || ^16.10.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {}
|
|
74
|
+
}
|