@nuxt/webpack-builder 4.3.0 → 4.3.1
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 +1 -1
- package/dist/THIRD-PARTY-LICENSES.md +115 -0
- package/dist/_chunks/libs/@vue/shared.d.mts +119 -0
- package/dist/_chunks/libs/pkg-types.d.mts +23 -0
- package/dist/index.d.mts +50462 -1
- package/dist/index.mjs +107 -191
- package/dist/loaders/vue-module-identifier.mjs +1 -6
- package/package.json +15 -15
package/dist/index.mjs
CHANGED
|
@@ -36,8 +36,6 @@ import { normalizeWebpackManifest, precomputeDependencies } from "vue-bundle-ren
|
|
|
36
36
|
import { hash } from "ohash";
|
|
37
37
|
import { serialize } from "seroval";
|
|
38
38
|
import { parseNodeModulePath } from "mlly";
|
|
39
|
-
|
|
40
|
-
//#region src/plugins/dynamic-base.ts
|
|
41
39
|
const defaults = {
|
|
42
40
|
globalPublicPath: "__webpack_public_path__",
|
|
43
41
|
sourcemap: true
|
|
@@ -67,13 +65,7 @@ const DynamicBasePlugin = createUnplugin((options = {}) => {
|
|
|
67
65
|
}
|
|
68
66
|
};
|
|
69
67
|
});
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region builder.mjs
|
|
73
68
|
const builder = "webpack";
|
|
74
|
-
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/plugins/chunk.ts
|
|
77
69
|
const pluginName = "ChunkErrorPlugin";
|
|
78
70
|
var ChunkErrorPlugin = class {
|
|
79
71
|
apply(compiler) {
|
|
@@ -105,16 +97,13 @@ if (typeof ${ensureChunk} !== "undefined") {
|
|
|
105
97
|
`;
|
|
106
98
|
}
|
|
107
99
|
};
|
|
108
|
-
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region src/plugins/ssr-styles.ts
|
|
111
100
|
const CSS_URL_RE = /url\((['"]?)(\/[^)]+?)\1\)/g;
|
|
112
101
|
const isVueFile = (id) => /\.vue(?:\?|$)/.test(id);
|
|
113
102
|
const isCSSLike = (name) => /\.(?:css|scss|sass|less|styl(?:us)?|postcss|pcss)(?:\?|$)/.test(name);
|
|
114
|
-
function normalizePath(nuxt
|
|
103
|
+
function normalizePath(nuxt, id) {
|
|
115
104
|
if (!id) return null;
|
|
116
105
|
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
117
|
-
const rel = relative(nuxt
|
|
106
|
+
const rel = relative(nuxt.options.srcDir, pathname);
|
|
118
107
|
if (rel.startsWith("..")) return null;
|
|
119
108
|
return rel;
|
|
120
109
|
}
|
|
@@ -134,12 +123,12 @@ function extractVueStyles(filePath) {
|
|
|
134
123
|
const styles = [];
|
|
135
124
|
const scopeId = createHash("sha256").update(filePath).digest("hex").slice(0, 8);
|
|
136
125
|
for (let i = 0; i < descriptor.styles.length; i++) {
|
|
137
|
-
const style
|
|
126
|
+
const style = descriptor.styles[i];
|
|
138
127
|
const result = compileStyle({
|
|
139
|
-
source: style
|
|
128
|
+
source: style.content,
|
|
140
129
|
filename: filePath,
|
|
141
130
|
id: `data-v-${scopeId}`,
|
|
142
|
-
scoped: style
|
|
131
|
+
scoped: style.scoped
|
|
143
132
|
});
|
|
144
133
|
if (!result.errors.length && result.code) styles.push(normalizeCSSContent(result.code));
|
|
145
134
|
}
|
|
@@ -153,10 +142,10 @@ var SSRStylesPlugin = class {
|
|
|
153
142
|
clientCSSByIssuer = /* @__PURE__ */ new Map();
|
|
154
143
|
chunksWithInlinedCSS = /* @__PURE__ */ new Set();
|
|
155
144
|
globalCSSPaths = /* @__PURE__ */ new Set();
|
|
156
|
-
constructor(nuxt
|
|
157
|
-
this.nuxt = nuxt
|
|
145
|
+
constructor(nuxt) {
|
|
146
|
+
this.nuxt = nuxt;
|
|
158
147
|
this.globalCSSPaths = this.resolveGlobalCSS();
|
|
159
|
-
nuxt
|
|
148
|
+
nuxt.hook("build:manifest", (manifest) => {
|
|
160
149
|
for (const [id, chunk] of Object.entries(manifest)) {
|
|
161
150
|
if (chunk.isEntry && chunk.src) this.chunksWithInlinedCSS.add(chunk.src);
|
|
162
151
|
else if (this.chunksWithInlinedCSS.has(id)) chunk.css &&= [];
|
|
@@ -182,9 +171,9 @@ var SSRStylesPlugin = class {
|
|
|
182
171
|
isPublicAsset(url, nitro) {
|
|
183
172
|
const cleaned = url.replace(/[?#].*$/, "");
|
|
184
173
|
for (const dir of nitro.options.publicAssets) {
|
|
185
|
-
const base
|
|
186
|
-
if (!url.startsWith(base
|
|
187
|
-
if (existsSync(cleaned.replace(base
|
|
174
|
+
const base = withTrailingSlash(dir.baseURL || "/");
|
|
175
|
+
if (!url.startsWith(base)) continue;
|
|
176
|
+
if (existsSync(cleaned.replace(base, withTrailingSlash(dir.dir)))) return true;
|
|
188
177
|
}
|
|
189
178
|
return false;
|
|
190
179
|
}
|
|
@@ -264,8 +253,8 @@ var SSRStylesPlugin = class {
|
|
|
264
253
|
});
|
|
265
254
|
}
|
|
266
255
|
emitServerStyles(compilation) {
|
|
267
|
-
const { webpack
|
|
268
|
-
const stage = webpack
|
|
256
|
+
const { webpack } = compilation.compiler;
|
|
257
|
+
const stage = webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE;
|
|
269
258
|
compilation.hooks.processAssets.tap({
|
|
270
259
|
name: "SSRStylesPlugin",
|
|
271
260
|
stage
|
|
@@ -295,10 +284,10 @@ var SSRStylesPlugin = class {
|
|
|
295
284
|
if (vueStyles.length) collected.set(rel, new Set(vueStyles));
|
|
296
285
|
}
|
|
297
286
|
const emitted = {};
|
|
298
|
-
const rawSource = webpack
|
|
287
|
+
const rawSource = webpack.sources.RawSource;
|
|
299
288
|
for (const [rel, cssSet] of collected.entries()) {
|
|
300
289
|
if (!cssSet.size) continue;
|
|
301
|
-
const transformed = Array.from(cssSet).map((style
|
|
290
|
+
const transformed = Array.from(cssSet).map((style) => this.rewriteStyle(style, nitro));
|
|
302
291
|
const needsPublicAssets = transformed.some((t) => t.needsPublicAsset);
|
|
303
292
|
const needsBuildAssets = transformed.some((t) => t.needsBuildAsset);
|
|
304
293
|
const imports = [];
|
|
@@ -365,8 +354,8 @@ var SSRStylesPlugin = class {
|
|
|
365
354
|
});
|
|
366
355
|
}
|
|
367
356
|
collectCSS(compilation) {
|
|
368
|
-
const { webpack
|
|
369
|
-
const stage = compilation.compiler.options.name === "server" ? webpack
|
|
357
|
+
const { webpack } = compilation.compiler;
|
|
358
|
+
const stage = compilation.compiler.options.name === "server" ? webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS : webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER;
|
|
370
359
|
const chunkCSSMeta = /* @__PURE__ */ new Map();
|
|
371
360
|
compilation.hooks.processAssets.tap({
|
|
372
361
|
name: "SSRStylesPlugin",
|
|
@@ -425,9 +414,6 @@ var SSRStylesPlugin = class {
|
|
|
425
414
|
return cssChunks;
|
|
426
415
|
}
|
|
427
416
|
};
|
|
428
|
-
|
|
429
|
-
//#endregion
|
|
430
|
-
//#region src/utils/mfs.ts
|
|
431
417
|
function createMFS() {
|
|
432
418
|
const _fs = { ...createFsFromVolume(new Volume()) };
|
|
433
419
|
_fs.join = join;
|
|
@@ -435,24 +421,17 @@ function createMFS() {
|
|
|
435
421
|
_fs.readFile = pify(_fs.readFile);
|
|
436
422
|
return _fs;
|
|
437
423
|
}
|
|
438
|
-
|
|
439
|
-
//#endregion
|
|
440
|
-
//#region src/utils/index.ts
|
|
441
|
-
/** @since 3.9.0 */
|
|
442
424
|
function toArray(value) {
|
|
443
425
|
return Array.isArray(value) ? value : [value];
|
|
444
426
|
}
|
|
445
|
-
|
|
446
|
-
//#endregion
|
|
447
|
-
//#region src/utils/config.ts
|
|
448
|
-
function createWebpackConfigContext(nuxt$1) {
|
|
427
|
+
function createWebpackConfigContext(nuxt) {
|
|
449
428
|
return {
|
|
450
|
-
nuxt
|
|
451
|
-
options: nuxt
|
|
452
|
-
userConfig: nuxt
|
|
429
|
+
nuxt,
|
|
430
|
+
options: nuxt.options,
|
|
431
|
+
userConfig: nuxt.options.webpack,
|
|
453
432
|
config: {},
|
|
454
433
|
name: "base",
|
|
455
|
-
isDev: nuxt
|
|
434
|
+
isDev: nuxt.options.dev,
|
|
456
435
|
isServer: false,
|
|
457
436
|
isClient: false,
|
|
458
437
|
alias: {},
|
|
@@ -464,17 +443,14 @@ async function applyPresets(ctx, presets) {
|
|
|
464
443
|
else await preset(ctx);
|
|
465
444
|
}
|
|
466
445
|
function fileName(ctx, key) {
|
|
467
|
-
let fileName
|
|
468
|
-
if (typeof fileName
|
|
469
|
-
if (typeof fileName
|
|
470
|
-
const hash
|
|
471
|
-
if (hash
|
|
446
|
+
let fileName = ctx.userConfig.filenames[key];
|
|
447
|
+
if (typeof fileName === "function") fileName = fileName(ctx);
|
|
448
|
+
if (typeof fileName === "string" && ctx.options.dev) {
|
|
449
|
+
const hash = /\[(chunkhash|contenthash|hash)(?::\d+)?\]/.exec(fileName);
|
|
450
|
+
if (hash) logger.warn(`Notice: Please do not use ${hash[1]} in dev mode to prevent memory leak`);
|
|
472
451
|
}
|
|
473
|
-
return fileName
|
|
452
|
+
return fileName;
|
|
474
453
|
}
|
|
475
|
-
|
|
476
|
-
//#endregion
|
|
477
|
-
//#region src/presets/assets.ts
|
|
478
454
|
function assets(ctx) {
|
|
479
455
|
ctx.config.module.rules.push({
|
|
480
456
|
test: /\.(png|jpe?g|gif|svg|webp)$/i,
|
|
@@ -505,9 +481,6 @@ function assets(ctx) {
|
|
|
505
481
|
}]
|
|
506
482
|
});
|
|
507
483
|
}
|
|
508
|
-
|
|
509
|
-
//#endregion
|
|
510
|
-
//#region src/plugins/warning-ignore.ts
|
|
511
484
|
var WarningIgnorePlugin = class {
|
|
512
485
|
filter;
|
|
513
486
|
constructor(filter) {
|
|
@@ -519,13 +492,6 @@ var WarningIgnorePlugin = class {
|
|
|
519
492
|
});
|
|
520
493
|
}
|
|
521
494
|
};
|
|
522
|
-
|
|
523
|
-
//#endregion
|
|
524
|
-
//#region src/plugins/vue/util.ts
|
|
525
|
-
/**
|
|
526
|
-
* This file is based on Vue.js (MIT) webpack plugins
|
|
527
|
-
* https://github.com/vuejs/vue/blob/dev/src/server/webpack-plugin/util.js
|
|
528
|
-
*/
|
|
529
495
|
const validate = (compiler) => {
|
|
530
496
|
if (compiler.options.target !== "node") logger.warn("webpack config `target` should be \"node\".");
|
|
531
497
|
if (!compiler.options.externals) logger.info("It is recommended to externalize dependencies in the server build for better build performance.");
|
|
@@ -536,36 +502,28 @@ const extractQueryPartJS = (file) => isJSRegExp.exec(file)?.[1];
|
|
|
536
502
|
const isCSSRegExp = /\.css(?:\?[^.]+)?$/;
|
|
537
503
|
const isCSS = (file) => isCSSRegExp.test(file);
|
|
538
504
|
const isHotUpdate = (file) => file.includes("hot-update");
|
|
539
|
-
|
|
540
|
-
//#endregion
|
|
541
|
-
//#region src/plugins/rollup-compat-dynamic-import.ts
|
|
542
505
|
const DYNAMIC_IMPORT_RE = /import\([^)]*\+\s*__webpack_require__[^+]*\)\.then/;
|
|
543
506
|
const DYNAMIC_IMPORT_REPLACE_RE = /import\([^)]*\+\s*(__webpack_require__[^+]*)\)\.then/g;
|
|
544
507
|
const HELPER_FILENAME = "_dynamic-import-helper.mjs";
|
|
545
508
|
const HELPER_IMPORT = `import { _rollupDynamicImport } from "./${HELPER_FILENAME}";\n`;
|
|
546
|
-
/**
|
|
547
|
-
* Webpack plugin that generates rollup-compatible dynamic imports.
|
|
548
|
-
* This plugin uses webpack's native compilation hooks to override dynamic import generation
|
|
549
|
-
* and create rollup-compatible code directly during webpack's compilation process.
|
|
550
|
-
*/
|
|
551
509
|
var RollupCompatDynamicImportPlugin = class {
|
|
552
510
|
apply(compiler) {
|
|
553
511
|
compiler.hooks.compilation.tap("RollupCompatDynamicImportPlugin", (compilation) => {
|
|
554
512
|
compilation.hooks.processAssets.tapAsync({
|
|
555
513
|
name: "RollupCompatDynamicImportPlugin",
|
|
556
514
|
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE
|
|
557
|
-
}, (assets
|
|
515
|
+
}, (assets, callback) => {
|
|
558
516
|
try {
|
|
559
517
|
const targetFiles = /* @__PURE__ */ new Set();
|
|
560
518
|
for (const chunk of compilation.chunks) if (chunk.canBeInitial() || chunk.hasRuntime()) for (const file of chunk.files || []) targetFiles.add(file);
|
|
561
|
-
for (const [filename, asset] of Object.entries(assets
|
|
519
|
+
for (const [filename, asset] of Object.entries(assets)) {
|
|
562
520
|
if (!isJS(filename)) continue;
|
|
563
521
|
if (!targetFiles.has(filename)) continue;
|
|
564
522
|
const source = asset.source();
|
|
565
523
|
const originalCode = typeof source === "string" ? source : source.toString();
|
|
566
524
|
if (!DYNAMIC_IMPORT_RE.test(originalCode)) continue;
|
|
567
525
|
const transformedCode = this.transformDynamicImports(originalCode);
|
|
568
|
-
if (transformedCode !== originalCode) assets
|
|
526
|
+
if (transformedCode !== originalCode) assets[filename] = new compiler.webpack.sources.RawSource(transformedCode);
|
|
569
527
|
}
|
|
570
528
|
this.generateDynamicImportHelper(compilation);
|
|
571
529
|
callback();
|
|
@@ -615,9 +573,6 @@ export function _rollupDynamicImport(chunkId) {
|
|
|
615
573
|
`;
|
|
616
574
|
}
|
|
617
575
|
};
|
|
618
|
-
|
|
619
|
-
//#endregion
|
|
620
|
-
//#region src/presets/base.ts
|
|
621
576
|
async function base(ctx) {
|
|
622
577
|
await applyPresets(ctx, [
|
|
623
578
|
baseAlias,
|
|
@@ -793,9 +748,6 @@ const statsMap = {
|
|
|
793
748
|
info: "normal",
|
|
794
749
|
verbose: "verbose"
|
|
795
750
|
};
|
|
796
|
-
|
|
797
|
-
//#endregion
|
|
798
|
-
//#region src/presets/esbuild.ts
|
|
799
751
|
function esbuild(ctx) {
|
|
800
752
|
const target = ctx.isServer ? "es2020" : "chrome85";
|
|
801
753
|
ctx.config.optimization.minimizer.push(new EsbuildPlugin());
|
|
@@ -823,9 +775,6 @@ function esbuild(ctx) {
|
|
|
823
775
|
}
|
|
824
776
|
});
|
|
825
777
|
}
|
|
826
|
-
|
|
827
|
-
//#endregion
|
|
828
|
-
//#region src/presets/pug.ts
|
|
829
778
|
function pug(ctx) {
|
|
830
779
|
ctx.config.module.rules.push({
|
|
831
780
|
test: /\.pug$/i,
|
|
@@ -841,35 +790,32 @@ function pug(ctx) {
|
|
|
841
790
|
}] }]
|
|
842
791
|
});
|
|
843
792
|
}
|
|
844
|
-
|
|
845
|
-
//#endregion
|
|
846
|
-
//#region src/utils/postcss.ts
|
|
847
793
|
const isPureObject = (obj) => obj !== null && !Array.isArray(obj) && typeof obj === "object";
|
|
848
794
|
function sortPlugins({ plugins, order }) {
|
|
849
795
|
const names = Object.keys(plugins);
|
|
850
796
|
return typeof order === "function" ? order(names) : order || names;
|
|
851
797
|
}
|
|
852
|
-
async function getPostcssConfig(nuxt
|
|
853
|
-
if (!nuxt
|
|
854
|
-
const postcssOptions = defu({}, nuxt
|
|
798
|
+
async function getPostcssConfig(nuxt) {
|
|
799
|
+
if (!nuxt.options.webpack.postcss || !nuxt.options.postcss) return false;
|
|
800
|
+
const postcssOptions = defu({}, nuxt.options.postcss, {
|
|
855
801
|
plugins: {
|
|
856
802
|
"postcss-import": { resolve: createResolver({
|
|
857
|
-
alias: { ...nuxt
|
|
858
|
-
modules: nuxt
|
|
803
|
+
alias: { ...nuxt.options.alias },
|
|
804
|
+
modules: nuxt.options.modulesDir
|
|
859
805
|
}) },
|
|
860
806
|
"postcss-url": {}
|
|
861
807
|
},
|
|
862
|
-
sourceMap: nuxt
|
|
808
|
+
sourceMap: nuxt.options.webpack.cssSourceMap
|
|
863
809
|
});
|
|
864
|
-
const jiti = createJiti(nuxt
|
|
810
|
+
const jiti = createJiti(nuxt.options.rootDir, { alias: nuxt.options.alias });
|
|
865
811
|
if (!Array.isArray(postcssOptions.plugins) && isPureObject(postcssOptions.plugins)) {
|
|
866
812
|
const plugins = [];
|
|
867
|
-
for (const pluginName
|
|
868
|
-
const pluginOptions = postcssOptions.plugins[pluginName
|
|
813
|
+
for (const pluginName of sortPlugins(postcssOptions)) {
|
|
814
|
+
const pluginOptions = postcssOptions.plugins[pluginName];
|
|
869
815
|
if (!pluginOptions) continue;
|
|
870
816
|
let pluginFn;
|
|
871
|
-
for (const parentURL of nuxt
|
|
872
|
-
pluginFn = await jiti.import(pluginName
|
|
817
|
+
for (const parentURL of nuxt.options.modulesDir) {
|
|
818
|
+
pluginFn = await jiti.import(pluginName, {
|
|
873
819
|
parentURL: parentURL.replace(/\/node_modules\/?$/, ""),
|
|
874
820
|
try: true,
|
|
875
821
|
default: true
|
|
@@ -879,19 +825,16 @@ async function getPostcssConfig(nuxt$1) {
|
|
|
879
825
|
break;
|
|
880
826
|
}
|
|
881
827
|
}
|
|
882
|
-
if (typeof pluginFn !== "function") console.warn(`[nuxt] could not import postcss plugin \`${pluginName
|
|
828
|
+
if (typeof pluginFn !== "function") console.warn(`[nuxt] could not import postcss plugin \`${pluginName}\`. Please report this as a bug.`);
|
|
883
829
|
}
|
|
884
830
|
postcssOptions.plugins = plugins;
|
|
885
831
|
}
|
|
886
832
|
return {
|
|
887
|
-
sourceMap: nuxt
|
|
888
|
-
...nuxt
|
|
833
|
+
sourceMap: nuxt.options.webpack.cssSourceMap,
|
|
834
|
+
...nuxt.options.webpack.postcss,
|
|
889
835
|
postcssOptions
|
|
890
836
|
};
|
|
891
837
|
}
|
|
892
|
-
|
|
893
|
-
//#endregion
|
|
894
|
-
//#region src/presets/style.ts
|
|
895
838
|
async function style(ctx) {
|
|
896
839
|
await applyPresets(ctx, [
|
|
897
840
|
loaders,
|
|
@@ -971,13 +914,6 @@ async function createPostcssLoadersRule(ctx) {
|
|
|
971
914
|
options: config
|
|
972
915
|
};
|
|
973
916
|
}
|
|
974
|
-
|
|
975
|
-
//#endregion
|
|
976
|
-
//#region src/plugins/vue/client.ts
|
|
977
|
-
/**
|
|
978
|
-
* This file is based on Vue.js (MIT) webpack plugins
|
|
979
|
-
* https://github.com/vuejs/vue/blob/dev/src/server/webpack-plugin/client.js
|
|
980
|
-
*/
|
|
981
917
|
var VueSSRClientPlugin = class {
|
|
982
918
|
serverDist;
|
|
983
919
|
nuxt;
|
|
@@ -995,9 +931,9 @@ var VueSSRClientPlugin = class {
|
|
|
995
931
|
const stats = compilation.getStats().toJson();
|
|
996
932
|
const context = this.nuxt.options.srcDir;
|
|
997
933
|
const initialFiles = /* @__PURE__ */ new Set();
|
|
998
|
-
for (const { assets
|
|
999
|
-
if (!assets
|
|
1000
|
-
for (const asset of assets
|
|
934
|
+
for (const { assets } of Object.values(stats.entrypoints)) {
|
|
935
|
+
if (!assets) continue;
|
|
936
|
+
for (const asset of assets) {
|
|
1001
937
|
const file = asset.name;
|
|
1002
938
|
if ((isJS(file) || isCSS(file)) && !isHotUpdate(file)) initialFiles.add(file);
|
|
1003
939
|
}
|
|
@@ -1043,11 +979,11 @@ var VueSSRClientPlugin = class {
|
|
|
1043
979
|
const files = Array.from(filesSet);
|
|
1044
980
|
webpackManifest.modules[relativeId] = files;
|
|
1045
981
|
if (Array.isArray(m.modules)) for (const concatenatedModule of m.modules) {
|
|
1046
|
-
const relativeId
|
|
1047
|
-
webpackManifest.modules[relativeId
|
|
982
|
+
const relativeId = this.getRelativeModuleId(concatenatedModule.identifier, context);
|
|
983
|
+
webpackManifest.modules[relativeId] ||= files;
|
|
1048
984
|
}
|
|
1049
985
|
if (stats.modules) {
|
|
1050
|
-
for (const m
|
|
986
|
+
for (const m of stats.modules) if (m.assets?.length && m.chunks?.includes(cid)) files.push(...m.assets.map(fileToIndex));
|
|
1051
987
|
}
|
|
1052
988
|
}
|
|
1053
989
|
const manifest = normalizeWebpackManifest(webpackManifest);
|
|
@@ -1060,9 +996,6 @@ var VueSSRClientPlugin = class {
|
|
|
1060
996
|
});
|
|
1061
997
|
}
|
|
1062
998
|
};
|
|
1063
|
-
|
|
1064
|
-
//#endregion
|
|
1065
|
-
//#region src/plugins/vue/server.ts
|
|
1066
999
|
const JS_MAP_RE = /\.js\.map$/;
|
|
1067
1000
|
var VueSSRServerPlugin = class {
|
|
1068
1001
|
options;
|
|
@@ -1075,7 +1008,7 @@ var VueSSRServerPlugin = class {
|
|
|
1075
1008
|
compilation.hooks.processAssets.tapAsync({
|
|
1076
1009
|
name: "VueSSRServerPlugin",
|
|
1077
1010
|
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
1078
|
-
}, (assets
|
|
1011
|
+
}, (assets, cb) => {
|
|
1079
1012
|
const stats = compilation.getStats().toJson();
|
|
1080
1013
|
const [entryName] = Object.keys(stats.entrypoints);
|
|
1081
1014
|
const entryInfo = stats.entrypoints[entryName];
|
|
@@ -1084,24 +1017,24 @@ var VueSSRServerPlugin = class {
|
|
|
1084
1017
|
if (entryAssets.length > 1) throw new Error("Server-side bundle should have one single entry file. Avoid using CommonsChunkPlugin in the server config.");
|
|
1085
1018
|
const [entry] = entryAssets;
|
|
1086
1019
|
if (!entry || typeof entry.name !== "string") throw new Error(`Entry "${entryName}" not found. Did you specify the correct entry option?`);
|
|
1087
|
-
const bundle
|
|
1020
|
+
const bundle = {
|
|
1088
1021
|
entry: entry.name,
|
|
1089
1022
|
files: {},
|
|
1090
1023
|
maps: {}
|
|
1091
1024
|
};
|
|
1092
1025
|
for (const asset of stats.assets) if (isJS(asset.name)) {
|
|
1093
1026
|
const queryPart = extractQueryPartJS(asset.name);
|
|
1094
|
-
if (queryPart !== void 0) bundle
|
|
1095
|
-
else bundle
|
|
1096
|
-
} else if (JS_MAP_RE.test(asset.name)) bundle
|
|
1097
|
-
else delete assets
|
|
1098
|
-
const src = JSON.stringify(bundle
|
|
1099
|
-
assets
|
|
1027
|
+
if (queryPart !== void 0) bundle.files[asset.name] = asset.name.replace(queryPart, "");
|
|
1028
|
+
else bundle.files[asset.name] = asset.name;
|
|
1029
|
+
} else if (JS_MAP_RE.test(asset.name)) bundle.maps[asset.name.replace(/\.map$/, "")] = asset.name;
|
|
1030
|
+
else delete assets[asset.name];
|
|
1031
|
+
const src = JSON.stringify(bundle, null, 2);
|
|
1032
|
+
assets[this.options.filename] = {
|
|
1100
1033
|
source: () => src,
|
|
1101
1034
|
size: () => src.length
|
|
1102
1035
|
};
|
|
1103
1036
|
const mjsSrc = "export default " + src;
|
|
1104
|
-
assets
|
|
1037
|
+
assets[this.options.filename.replace(".json", ".mjs")] = {
|
|
1105
1038
|
source: () => mjsSrc,
|
|
1106
1039
|
map: () => null,
|
|
1107
1040
|
size: () => mjsSrc.length
|
|
@@ -1111,9 +1044,6 @@ var VueSSRServerPlugin = class {
|
|
|
1111
1044
|
});
|
|
1112
1045
|
}
|
|
1113
1046
|
};
|
|
1114
|
-
|
|
1115
|
-
//#endregion
|
|
1116
|
-
//#region src/presets/vue.ts
|
|
1117
1047
|
function vue(ctx) {
|
|
1118
1048
|
ctx.config.plugins.push(new (VueLoaderPlugin.default || VueLoaderPlugin)());
|
|
1119
1049
|
ctx.config.module.rules.push({
|
|
@@ -1143,9 +1073,6 @@ function vue(ctx) {
|
|
|
1143
1073
|
"__VUE_PROD_HYDRATION_MISMATCH_DETAILS__": ctx.nuxt.options.debug && ctx.nuxt.options.debug.hydration
|
|
1144
1074
|
}));
|
|
1145
1075
|
}
|
|
1146
|
-
|
|
1147
|
-
//#endregion
|
|
1148
|
-
//#region src/presets/nuxt.ts
|
|
1149
1076
|
async function nuxt(ctx) {
|
|
1150
1077
|
await applyPresets(ctx, [
|
|
1151
1078
|
base,
|
|
@@ -1156,9 +1083,6 @@ async function nuxt(ctx) {
|
|
|
1156
1083
|
vue
|
|
1157
1084
|
]);
|
|
1158
1085
|
}
|
|
1159
|
-
|
|
1160
|
-
//#endregion
|
|
1161
|
-
//#region src/configs/client.ts
|
|
1162
1086
|
async function client(ctx) {
|
|
1163
1087
|
ctx.name = "client";
|
|
1164
1088
|
ctx.isClient = true;
|
|
@@ -1264,9 +1188,6 @@ function clientPlugins(ctx) {
|
|
|
1264
1188
|
if (!ctx.nuxt.options.test && (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev)) ctx.config.plugins.push(new TsCheckerPlugin({ logger }));
|
|
1265
1189
|
}
|
|
1266
1190
|
}
|
|
1267
|
-
|
|
1268
|
-
//#endregion
|
|
1269
|
-
//#region src/presets/node.ts
|
|
1270
1191
|
function node(ctx) {
|
|
1271
1192
|
ctx.config.target = "node";
|
|
1272
1193
|
ctx.config.node = false;
|
|
@@ -1295,9 +1216,6 @@ function node(ctx) {
|
|
|
1295
1216
|
maxAssetSize: Number.POSITIVE_INFINITY
|
|
1296
1217
|
};
|
|
1297
1218
|
}
|
|
1298
|
-
|
|
1299
|
-
//#endregion
|
|
1300
|
-
//#region src/configs/server.ts
|
|
1301
1219
|
const assetPattern = /\.(?:css|s[ca]ss|png|jpe?g|gif|svg|woff2?|eot|ttf|otf|webp|webm|mp4|ogv)(?:\?.*)?$/i;
|
|
1302
1220
|
const VIRTUAL_RE = /^\0?virtual:(?:nuxt:)?/;
|
|
1303
1221
|
async function server(ctx) {
|
|
@@ -1390,117 +1308,117 @@ function serverPlugins(ctx) {
|
|
|
1390
1308
|
}));
|
|
1391
1309
|
if (!ctx.nuxt.options.test && (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev)) ctx.config.plugins.push(new TsCheckerPlugin({ logger }));
|
|
1392
1310
|
}
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
const webpackConfigs = await Promise.all([client, ...nuxt$1.options.ssr ? [server] : []].map(async (preset) => {
|
|
1398
|
-
const ctx = createWebpackConfigContext(nuxt$1);
|
|
1399
|
-
ctx.userConfig = defu(nuxt$1.options.webpack[`$${preset.name}`], ctx.userConfig);
|
|
1311
|
+
const bundle = async (nuxt) => {
|
|
1312
|
+
const webpackConfigs = await Promise.all([client, ...nuxt.options.ssr ? [server] : []].map(async (preset) => {
|
|
1313
|
+
const ctx = createWebpackConfigContext(nuxt);
|
|
1314
|
+
ctx.userConfig = defu(nuxt.options.webpack[`$${preset.name}`], ctx.userConfig);
|
|
1400
1315
|
await applyPresets(ctx, preset);
|
|
1401
1316
|
return ctx.config;
|
|
1402
1317
|
}));
|
|
1403
|
-
|
|
1404
|
-
if (!nuxt$1.options.dev) useNitro().hooks.hook("rollup:before", (_nitro, config) => {
|
|
1318
|
+
if (!nuxt.options.dev) useNitro().hooks.hook("rollup:before", (_nitro, config) => {
|
|
1405
1319
|
const plugins = config.plugins;
|
|
1406
1320
|
const existingPlugin = plugins.findIndex((i) => i && "name" in i && i.name === "dynamic-require");
|
|
1407
1321
|
if (existingPlugin >= 0) plugins.splice(existingPlugin, 1);
|
|
1408
1322
|
});
|
|
1409
|
-
await nuxt
|
|
1410
|
-
const mfs = nuxt
|
|
1411
|
-
const ssrStylesPlugin = nuxt
|
|
1323
|
+
await nuxt.callHook(`${builder}:config`, webpackConfigs);
|
|
1324
|
+
const mfs = nuxt.options.dev ? createMFS() : null;
|
|
1325
|
+
const ssrStylesPlugin = nuxt.options.ssr && !nuxt.options.dev && nuxt.options.features.inlineStyles ? new SSRStylesPlugin(nuxt) : null;
|
|
1412
1326
|
for (const config of webpackConfigs) {
|
|
1413
|
-
config.plugins.push(DynamicBasePlugin.webpack({ sourcemap: !!nuxt
|
|
1414
|
-
if (config.name === "client" && nuxt
|
|
1327
|
+
config.plugins.push(DynamicBasePlugin.webpack({ sourcemap: !!nuxt.options.sourcemap[config.name] }));
|
|
1328
|
+
if (config.name === "client" && nuxt.options.experimental.emitRouteChunkError && nuxt.options.builder !== "@nuxt/rspack-builder") config.plugins.push(new ChunkErrorPlugin());
|
|
1415
1329
|
if (ssrStylesPlugin) config.plugins.push(ssrStylesPlugin);
|
|
1416
1330
|
}
|
|
1417
|
-
await nuxt
|
|
1331
|
+
await nuxt.callHook(`${builder}:configResolved`, webpackConfigs);
|
|
1418
1332
|
const compilers = webpackConfigs.map((config) => {
|
|
1419
1333
|
const compiler = webpack(config);
|
|
1420
|
-
if (nuxt
|
|
1334
|
+
if (nuxt.options.dev && compiler) compiler.outputFileSystem = mfs;
|
|
1421
1335
|
return compiler;
|
|
1422
1336
|
});
|
|
1423
|
-
nuxt
|
|
1424
|
-
for (const compiler of compilers) await new Promise((resolve
|
|
1337
|
+
nuxt.hook("close", async () => {
|
|
1338
|
+
for (const compiler of compilers) await new Promise((resolve) => compiler.close(resolve));
|
|
1425
1339
|
});
|
|
1426
|
-
if (nuxt
|
|
1340
|
+
if (nuxt.options.dev) {
|
|
1427
1341
|
await Promise.all(compilers.map((c) => compile(c)));
|
|
1428
1342
|
return;
|
|
1429
1343
|
}
|
|
1430
1344
|
for (const c of compilers) await compile(c);
|
|
1431
1345
|
};
|
|
1432
1346
|
async function createDevMiddleware(compiler) {
|
|
1433
|
-
const nuxt
|
|
1347
|
+
const nuxt = useNuxt();
|
|
1434
1348
|
logger.debug("Creating webpack middleware...");
|
|
1435
1349
|
const devMiddleware = webpackDevMiddleware(compiler, {
|
|
1436
|
-
publicPath: joinURL(nuxt
|
|
1350
|
+
publicPath: joinURL(nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir),
|
|
1437
1351
|
outputFileSystem: compiler.outputFileSystem,
|
|
1438
1352
|
stats: "none",
|
|
1439
|
-
...nuxt
|
|
1353
|
+
...nuxt.options.webpack.devMiddleware
|
|
1440
1354
|
});
|
|
1441
|
-
nuxt
|
|
1442
|
-
const { client: _client, ...hotMiddlewareOptions } = nuxt
|
|
1355
|
+
nuxt.hook("close", () => pify(devMiddleware.close.bind(devMiddleware))());
|
|
1356
|
+
const { client: _client, ...hotMiddlewareOptions } = nuxt.options.webpack.hotMiddleware || {};
|
|
1443
1357
|
const hotMiddleware = webpackHotMiddleware(compiler, {
|
|
1444
1358
|
log: false,
|
|
1445
1359
|
heartbeat: 1e4,
|
|
1446
|
-
path: joinURL(nuxt
|
|
1360
|
+
path: joinURL(nuxt.options.app.baseURL, "__webpack_hmr", compiler.options.name),
|
|
1447
1361
|
...hotMiddlewareOptions
|
|
1448
1362
|
});
|
|
1449
1363
|
const devHandler = wdmToH3Handler(devMiddleware);
|
|
1450
|
-
await nuxt
|
|
1364
|
+
await nuxt.callHook("server:devHandler", defineEventHandler(async (event) => {
|
|
1451
1365
|
const body = await devHandler(event);
|
|
1452
1366
|
if (body !== void 0) return body;
|
|
1453
1367
|
const { req, res } = "runtime" in event ? event.runtime.node : event.node;
|
|
1454
|
-
await new Promise((resolve
|
|
1368
|
+
await new Promise((resolve, reject) => hotMiddleware(req, res, (err) => err ? reject(err) : resolve()));
|
|
1455
1369
|
}), { cors: () => true });
|
|
1456
1370
|
return devMiddleware;
|
|
1457
1371
|
}
|
|
1458
1372
|
function wdmToH3Handler(devMiddleware) {
|
|
1459
1373
|
return defineEventHandler(async (event) => {
|
|
1460
1374
|
const { req, res } = "runtime" in event ? event.runtime.node : event.node;
|
|
1461
|
-
if (req.headers["sec-fetch-mode"] === "no-cors" && req.headers["sec-fetch-site"] === "cross-site")
|
|
1375
|
+
if (req.headers["sec-fetch-mode"] === "no-cors" && req.headers["sec-fetch-site"] === "cross-site") {
|
|
1376
|
+
res.statusCode = 403;
|
|
1377
|
+
res.end("Forbidden");
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1462
1380
|
event.context.webpack = {
|
|
1463
1381
|
...event.context.webpack,
|
|
1464
1382
|
devMiddleware: devMiddleware.context
|
|
1465
1383
|
};
|
|
1466
|
-
return await new Promise((resolve
|
|
1384
|
+
return await new Promise((resolve, reject) => {
|
|
1467
1385
|
res.stream = (stream) => {
|
|
1468
|
-
resolve
|
|
1386
|
+
resolve(stream);
|
|
1469
1387
|
};
|
|
1470
1388
|
res.send = (data) => {
|
|
1471
|
-
resolve
|
|
1389
|
+
resolve(data);
|
|
1472
1390
|
};
|
|
1473
1391
|
res.finish = (data) => {
|
|
1474
|
-
resolve
|
|
1392
|
+
resolve(data);
|
|
1475
1393
|
};
|
|
1476
1394
|
devMiddleware(req, res, (err) => {
|
|
1477
1395
|
if (err) reject(err);
|
|
1478
|
-
else resolve
|
|
1396
|
+
else resolve(void 0);
|
|
1479
1397
|
});
|
|
1480
1398
|
});
|
|
1481
1399
|
});
|
|
1482
1400
|
}
|
|
1483
1401
|
async function compile(compiler) {
|
|
1484
|
-
const nuxt
|
|
1485
|
-
await nuxt
|
|
1402
|
+
const nuxt = useNuxt();
|
|
1403
|
+
await nuxt.callHook(`${builder}:compile`, {
|
|
1486
1404
|
name: compiler.options.name,
|
|
1487
1405
|
compiler
|
|
1488
1406
|
});
|
|
1489
|
-
compiler.hooks.done.tap("load-resources", async (stats
|
|
1490
|
-
await nuxt
|
|
1407
|
+
compiler.hooks.done.tap("load-resources", async (stats) => {
|
|
1408
|
+
await nuxt.callHook(`${builder}:compiled`, {
|
|
1491
1409
|
name: compiler.options.name,
|
|
1492
1410
|
compiler,
|
|
1493
|
-
stats
|
|
1411
|
+
stats
|
|
1494
1412
|
});
|
|
1495
1413
|
});
|
|
1496
|
-
if (nuxt
|
|
1414
|
+
if (nuxt.options.dev) {
|
|
1497
1415
|
const compilersWatching = [];
|
|
1498
|
-
nuxt
|
|
1416
|
+
nuxt.hook("close", async () => {
|
|
1499
1417
|
await Promise.all(compilersWatching.map((watching) => watching && pify(watching.close.bind(watching))()));
|
|
1500
1418
|
});
|
|
1501
|
-
if (compiler.options.name === "client") return new Promise((resolve
|
|
1419
|
+
if (compiler.options.name === "client") return new Promise((resolve, reject) => {
|
|
1502
1420
|
compiler.hooks.done.tap("nuxt-dev", () => {
|
|
1503
|
-
resolve
|
|
1421
|
+
resolve(null);
|
|
1504
1422
|
});
|
|
1505
1423
|
compiler.hooks.failed.tap("nuxt-errorlog", (err) => {
|
|
1506
1424
|
reject(err);
|
|
@@ -1509,15 +1427,15 @@ async function compile(compiler) {
|
|
|
1509
1427
|
if (devMiddleware.context.watching) compilersWatching.push(devMiddleware.context.watching);
|
|
1510
1428
|
});
|
|
1511
1429
|
});
|
|
1512
|
-
return new Promise((resolve
|
|
1513
|
-
const watching = compiler.watch(nuxt
|
|
1430
|
+
return new Promise((resolve, reject) => {
|
|
1431
|
+
const watching = compiler.watch(nuxt.options.watchers.webpack, (err) => {
|
|
1514
1432
|
if (err) return reject(err);
|
|
1515
|
-
resolve
|
|
1433
|
+
resolve(null);
|
|
1516
1434
|
});
|
|
1517
1435
|
compilersWatching.push(watching);
|
|
1518
1436
|
});
|
|
1519
1437
|
}
|
|
1520
|
-
const stats = await new Promise((resolve
|
|
1438
|
+
const stats = await new Promise((resolve, reject) => compiler.run((err, stats) => err ? reject(err) : resolve(stats)));
|
|
1521
1439
|
if (stats.hasErrors()) {
|
|
1522
1440
|
const error = /* @__PURE__ */ new Error("Nuxt build error");
|
|
1523
1441
|
error.stack = stats.toString("errors-only");
|
|
@@ -1527,6 +1445,4 @@ async function compile(compiler) {
|
|
|
1527
1445
|
function defineEventHandler(handler) {
|
|
1528
1446
|
return Object.assign(handler, { __is_handler__: true });
|
|
1529
1447
|
}
|
|
1530
|
-
|
|
1531
|
-
//#endregion
|
|
1532
|
-
export { bundle };
|
|
1448
|
+
export { bundle };
|