@nuxt/rspack-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 +106 -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 -188
- package/dist/loaders/vue-module-identifier.mjs +1 -6
- package/package.json +16 -16
package/dist/index.mjs
CHANGED
|
@@ -33,8 +33,6 @@ import { normalizeWebpackManifest, precomputeDependencies } from "vue-bundle-ren
|
|
|
33
33
|
import { hash } from "ohash";
|
|
34
34
|
import { serialize } from "seroval";
|
|
35
35
|
import { parseNodeModulePath } from "mlly";
|
|
36
|
-
|
|
37
|
-
//#region ../webpack/src/plugins/dynamic-base.ts
|
|
38
36
|
const defaults = {
|
|
39
37
|
globalPublicPath: "__webpack_public_path__",
|
|
40
38
|
sourcemap: true
|
|
@@ -64,9 +62,6 @@ const DynamicBasePlugin = createUnplugin((options = {}) => {
|
|
|
64
62
|
}
|
|
65
63
|
};
|
|
66
64
|
});
|
|
67
|
-
|
|
68
|
-
//#endregion
|
|
69
|
-
//#region ../webpack/src/plugins/chunk.ts
|
|
70
65
|
const pluginName = "ChunkErrorPlugin";
|
|
71
66
|
var ChunkErrorPlugin = class {
|
|
72
67
|
apply(compiler) {
|
|
@@ -98,16 +93,13 @@ if (typeof ${ensureChunk} !== "undefined") {
|
|
|
98
93
|
`;
|
|
99
94
|
}
|
|
100
95
|
};
|
|
101
|
-
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region ../webpack/src/plugins/ssr-styles.ts
|
|
104
96
|
const CSS_URL_RE = /url\((['"]?)(\/[^)]+?)\1\)/g;
|
|
105
97
|
const isVueFile = (id) => /\.vue(?:\?|$)/.test(id);
|
|
106
98
|
const isCSSLike = (name) => /\.(?:css|scss|sass|less|styl(?:us)?|postcss|pcss)(?:\?|$)/.test(name);
|
|
107
|
-
function normalizePath(nuxt
|
|
99
|
+
function normalizePath(nuxt, id) {
|
|
108
100
|
if (!id) return null;
|
|
109
101
|
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
110
|
-
const rel = relative(nuxt
|
|
102
|
+
const rel = relative(nuxt.options.srcDir, pathname);
|
|
111
103
|
if (rel.startsWith("..")) return null;
|
|
112
104
|
return rel;
|
|
113
105
|
}
|
|
@@ -127,12 +119,12 @@ function extractVueStyles(filePath) {
|
|
|
127
119
|
const styles = [];
|
|
128
120
|
const scopeId = createHash("sha256").update(filePath).digest("hex").slice(0, 8);
|
|
129
121
|
for (let i = 0; i < descriptor.styles.length; i++) {
|
|
130
|
-
const style
|
|
122
|
+
const style = descriptor.styles[i];
|
|
131
123
|
const result = compileStyle({
|
|
132
|
-
source: style
|
|
124
|
+
source: style.content,
|
|
133
125
|
filename: filePath,
|
|
134
126
|
id: `data-v-${scopeId}`,
|
|
135
|
-
scoped: style
|
|
127
|
+
scoped: style.scoped
|
|
136
128
|
});
|
|
137
129
|
if (!result.errors.length && result.code) styles.push(normalizeCSSContent(result.code));
|
|
138
130
|
}
|
|
@@ -146,10 +138,10 @@ var SSRStylesPlugin = class {
|
|
|
146
138
|
clientCSSByIssuer = /* @__PURE__ */ new Map();
|
|
147
139
|
chunksWithInlinedCSS = /* @__PURE__ */ new Set();
|
|
148
140
|
globalCSSPaths = /* @__PURE__ */ new Set();
|
|
149
|
-
constructor(nuxt
|
|
150
|
-
this.nuxt = nuxt
|
|
141
|
+
constructor(nuxt) {
|
|
142
|
+
this.nuxt = nuxt;
|
|
151
143
|
this.globalCSSPaths = this.resolveGlobalCSS();
|
|
152
|
-
nuxt
|
|
144
|
+
nuxt.hook("build:manifest", (manifest) => {
|
|
153
145
|
for (const [id, chunk] of Object.entries(manifest)) {
|
|
154
146
|
if (chunk.isEntry && chunk.src) this.chunksWithInlinedCSS.add(chunk.src);
|
|
155
147
|
else if (this.chunksWithInlinedCSS.has(id)) chunk.css &&= [];
|
|
@@ -175,9 +167,9 @@ var SSRStylesPlugin = class {
|
|
|
175
167
|
isPublicAsset(url, nitro) {
|
|
176
168
|
const cleaned = url.replace(/[?#].*$/, "");
|
|
177
169
|
for (const dir of nitro.options.publicAssets) {
|
|
178
|
-
const base
|
|
179
|
-
if (!url.startsWith(base
|
|
180
|
-
if (existsSync(cleaned.replace(base
|
|
170
|
+
const base = withTrailingSlash(dir.baseURL || "/");
|
|
171
|
+
if (!url.startsWith(base)) continue;
|
|
172
|
+
if (existsSync(cleaned.replace(base, withTrailingSlash(dir.dir)))) return true;
|
|
181
173
|
}
|
|
182
174
|
return false;
|
|
183
175
|
}
|
|
@@ -257,8 +249,8 @@ var SSRStylesPlugin = class {
|
|
|
257
249
|
});
|
|
258
250
|
}
|
|
259
251
|
emitServerStyles(compilation) {
|
|
260
|
-
const { webpack
|
|
261
|
-
const stage = webpack
|
|
252
|
+
const { webpack } = compilation.compiler;
|
|
253
|
+
const stage = webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE;
|
|
262
254
|
compilation.hooks.processAssets.tap({
|
|
263
255
|
name: "SSRStylesPlugin",
|
|
264
256
|
stage
|
|
@@ -288,10 +280,10 @@ var SSRStylesPlugin = class {
|
|
|
288
280
|
if (vueStyles.length) collected.set(rel, new Set(vueStyles));
|
|
289
281
|
}
|
|
290
282
|
const emitted = {};
|
|
291
|
-
const rawSource = webpack
|
|
283
|
+
const rawSource = webpack.sources.RawSource;
|
|
292
284
|
for (const [rel, cssSet] of collected.entries()) {
|
|
293
285
|
if (!cssSet.size) continue;
|
|
294
|
-
const transformed = Array.from(cssSet).map((style
|
|
286
|
+
const transformed = Array.from(cssSet).map((style) => this.rewriteStyle(style, nitro));
|
|
295
287
|
const needsPublicAssets = transformed.some((t) => t.needsPublicAsset);
|
|
296
288
|
const needsBuildAssets = transformed.some((t) => t.needsBuildAsset);
|
|
297
289
|
const imports = [];
|
|
@@ -358,8 +350,8 @@ var SSRStylesPlugin = class {
|
|
|
358
350
|
});
|
|
359
351
|
}
|
|
360
352
|
collectCSS(compilation) {
|
|
361
|
-
const { webpack
|
|
362
|
-
const stage = compilation.compiler.options.name === "server" ? webpack
|
|
353
|
+
const { webpack } = compilation.compiler;
|
|
354
|
+
const stage = compilation.compiler.options.name === "server" ? webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS : webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER;
|
|
363
355
|
const chunkCSSMeta = /* @__PURE__ */ new Map();
|
|
364
356
|
compilation.hooks.processAssets.tap({
|
|
365
357
|
name: "SSRStylesPlugin",
|
|
@@ -418,9 +410,6 @@ var SSRStylesPlugin = class {
|
|
|
418
410
|
return cssChunks;
|
|
419
411
|
}
|
|
420
412
|
};
|
|
421
|
-
|
|
422
|
-
//#endregion
|
|
423
|
-
//#region ../webpack/src/utils/mfs.ts
|
|
424
413
|
function createMFS() {
|
|
425
414
|
const _fs = { ...createFsFromVolume(new Volume()) };
|
|
426
415
|
_fs.join = join;
|
|
@@ -428,24 +417,17 @@ function createMFS() {
|
|
|
428
417
|
_fs.readFile = pify(_fs.readFile);
|
|
429
418
|
return _fs;
|
|
430
419
|
}
|
|
431
|
-
|
|
432
|
-
//#endregion
|
|
433
|
-
//#region ../webpack/src/utils/index.ts
|
|
434
|
-
/** @since 3.9.0 */
|
|
435
420
|
function toArray(value) {
|
|
436
421
|
return Array.isArray(value) ? value : [value];
|
|
437
422
|
}
|
|
438
|
-
|
|
439
|
-
//#endregion
|
|
440
|
-
//#region ../webpack/src/utils/config.ts
|
|
441
|
-
function createWebpackConfigContext(nuxt$1) {
|
|
423
|
+
function createWebpackConfigContext(nuxt) {
|
|
442
424
|
return {
|
|
443
|
-
nuxt
|
|
444
|
-
options: nuxt
|
|
445
|
-
userConfig: nuxt
|
|
425
|
+
nuxt,
|
|
426
|
+
options: nuxt.options,
|
|
427
|
+
userConfig: nuxt.options.webpack,
|
|
446
428
|
config: {},
|
|
447
429
|
name: "base",
|
|
448
|
-
isDev: nuxt
|
|
430
|
+
isDev: nuxt.options.dev,
|
|
449
431
|
isServer: false,
|
|
450
432
|
isClient: false,
|
|
451
433
|
alias: {},
|
|
@@ -457,17 +439,14 @@ async function applyPresets(ctx, presets) {
|
|
|
457
439
|
else await preset(ctx);
|
|
458
440
|
}
|
|
459
441
|
function fileName(ctx, key) {
|
|
460
|
-
let fileName
|
|
461
|
-
if (typeof fileName
|
|
462
|
-
if (typeof fileName
|
|
463
|
-
const hash
|
|
464
|
-
if (hash
|
|
442
|
+
let fileName = ctx.userConfig.filenames[key];
|
|
443
|
+
if (typeof fileName === "function") fileName = fileName(ctx);
|
|
444
|
+
if (typeof fileName === "string" && ctx.options.dev) {
|
|
445
|
+
const hash = /\[(chunkhash|contenthash|hash)(?::\d+)?\]/.exec(fileName);
|
|
446
|
+
if (hash) logger.warn(`Notice: Please do not use ${hash[1]} in dev mode to prevent memory leak`);
|
|
465
447
|
}
|
|
466
|
-
return fileName
|
|
448
|
+
return fileName;
|
|
467
449
|
}
|
|
468
|
-
|
|
469
|
-
//#endregion
|
|
470
|
-
//#region ../webpack/src/presets/assets.ts
|
|
471
450
|
function assets(ctx) {
|
|
472
451
|
ctx.config.module.rules.push({
|
|
473
452
|
test: /\.(png|jpe?g|gif|svg|webp)$/i,
|
|
@@ -498,9 +477,6 @@ function assets(ctx) {
|
|
|
498
477
|
}]
|
|
499
478
|
});
|
|
500
479
|
}
|
|
501
|
-
|
|
502
|
-
//#endregion
|
|
503
|
-
//#region ../webpack/src/plugins/warning-ignore.ts
|
|
504
480
|
var WarningIgnorePlugin = class {
|
|
505
481
|
filter;
|
|
506
482
|
constructor(filter) {
|
|
@@ -512,13 +488,6 @@ var WarningIgnorePlugin = class {
|
|
|
512
488
|
});
|
|
513
489
|
}
|
|
514
490
|
};
|
|
515
|
-
|
|
516
|
-
//#endregion
|
|
517
|
-
//#region ../webpack/src/plugins/vue/util.ts
|
|
518
|
-
/**
|
|
519
|
-
* This file is based on Vue.js (MIT) webpack plugins
|
|
520
|
-
* https://github.com/vuejs/vue/blob/dev/src/server/webpack-plugin/util.js
|
|
521
|
-
*/
|
|
522
491
|
const validate = (compiler) => {
|
|
523
492
|
if (compiler.options.target !== "node") logger.warn("webpack config `target` should be \"node\".");
|
|
524
493
|
if (!compiler.options.externals) logger.info("It is recommended to externalize dependencies in the server build for better build performance.");
|
|
@@ -529,36 +498,28 @@ const extractQueryPartJS = (file) => isJSRegExp.exec(file)?.[1];
|
|
|
529
498
|
const isCSSRegExp = /\.css(?:\?[^.]+)?$/;
|
|
530
499
|
const isCSS = (file) => isCSSRegExp.test(file);
|
|
531
500
|
const isHotUpdate = (file) => file.includes("hot-update");
|
|
532
|
-
|
|
533
|
-
//#endregion
|
|
534
|
-
//#region ../webpack/src/plugins/rollup-compat-dynamic-import.ts
|
|
535
501
|
const DYNAMIC_IMPORT_RE = /import\([^)]*\+\s*__webpack_require__[^+]*\)\.then/;
|
|
536
502
|
const DYNAMIC_IMPORT_REPLACE_RE = /import\([^)]*\+\s*(__webpack_require__[^+]*)\)\.then/g;
|
|
537
503
|
const HELPER_FILENAME = "_dynamic-import-helper.mjs";
|
|
538
504
|
const HELPER_IMPORT = `import { _rollupDynamicImport } from "./${HELPER_FILENAME}";\n`;
|
|
539
|
-
/**
|
|
540
|
-
* Webpack plugin that generates rollup-compatible dynamic imports.
|
|
541
|
-
* This plugin uses webpack's native compilation hooks to override dynamic import generation
|
|
542
|
-
* and create rollup-compatible code directly during webpack's compilation process.
|
|
543
|
-
*/
|
|
544
505
|
var RollupCompatDynamicImportPlugin = class {
|
|
545
506
|
apply(compiler) {
|
|
546
507
|
compiler.hooks.compilation.tap("RollupCompatDynamicImportPlugin", (compilation) => {
|
|
547
508
|
compilation.hooks.processAssets.tapAsync({
|
|
548
509
|
name: "RollupCompatDynamicImportPlugin",
|
|
549
510
|
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE
|
|
550
|
-
}, (assets
|
|
511
|
+
}, (assets, callback) => {
|
|
551
512
|
try {
|
|
552
513
|
const targetFiles = /* @__PURE__ */ new Set();
|
|
553
514
|
for (const chunk of compilation.chunks) if (chunk.canBeInitial() || chunk.hasRuntime()) for (const file of chunk.files || []) targetFiles.add(file);
|
|
554
|
-
for (const [filename, asset] of Object.entries(assets
|
|
515
|
+
for (const [filename, asset] of Object.entries(assets)) {
|
|
555
516
|
if (!isJS(filename)) continue;
|
|
556
517
|
if (!targetFiles.has(filename)) continue;
|
|
557
518
|
const source = asset.source();
|
|
558
519
|
const originalCode = typeof source === "string" ? source : source.toString();
|
|
559
520
|
if (!DYNAMIC_IMPORT_RE.test(originalCode)) continue;
|
|
560
521
|
const transformedCode = this.transformDynamicImports(originalCode);
|
|
561
|
-
if (transformedCode !== originalCode) assets
|
|
522
|
+
if (transformedCode !== originalCode) assets[filename] = new compiler.webpack.sources.RawSource(transformedCode);
|
|
562
523
|
}
|
|
563
524
|
this.generateDynamicImportHelper(compilation);
|
|
564
525
|
callback();
|
|
@@ -608,9 +569,6 @@ export function _rollupDynamicImport(chunkId) {
|
|
|
608
569
|
`;
|
|
609
570
|
}
|
|
610
571
|
};
|
|
611
|
-
|
|
612
|
-
//#endregion
|
|
613
|
-
//#region ../webpack/src/presets/base.ts
|
|
614
572
|
async function base(ctx) {
|
|
615
573
|
await applyPresets(ctx, [
|
|
616
574
|
baseAlias,
|
|
@@ -786,9 +744,6 @@ const statsMap = {
|
|
|
786
744
|
info: "normal",
|
|
787
745
|
verbose: "verbose"
|
|
788
746
|
};
|
|
789
|
-
|
|
790
|
-
//#endregion
|
|
791
|
-
//#region ../webpack/src/presets/esbuild.ts
|
|
792
747
|
function esbuild(ctx) {
|
|
793
748
|
const target = ctx.isServer ? "es2020" : "chrome85";
|
|
794
749
|
ctx.config.optimization.minimizer.push(new EsbuildPlugin());
|
|
@@ -816,9 +771,6 @@ function esbuild(ctx) {
|
|
|
816
771
|
}
|
|
817
772
|
});
|
|
818
773
|
}
|
|
819
|
-
|
|
820
|
-
//#endregion
|
|
821
|
-
//#region ../webpack/src/presets/pug.ts
|
|
822
774
|
function pug(ctx) {
|
|
823
775
|
ctx.config.module.rules.push({
|
|
824
776
|
test: /\.pug$/i,
|
|
@@ -834,35 +786,32 @@ function pug(ctx) {
|
|
|
834
786
|
}] }]
|
|
835
787
|
});
|
|
836
788
|
}
|
|
837
|
-
|
|
838
|
-
//#endregion
|
|
839
|
-
//#region ../webpack/src/utils/postcss.ts
|
|
840
789
|
const isPureObject = (obj) => obj !== null && !Array.isArray(obj) && typeof obj === "object";
|
|
841
790
|
function sortPlugins({ plugins, order }) {
|
|
842
791
|
const names = Object.keys(plugins);
|
|
843
792
|
return typeof order === "function" ? order(names) : order || names;
|
|
844
793
|
}
|
|
845
|
-
async function getPostcssConfig(nuxt
|
|
846
|
-
if (!nuxt
|
|
847
|
-
const postcssOptions = defu({}, nuxt
|
|
794
|
+
async function getPostcssConfig(nuxt) {
|
|
795
|
+
if (!nuxt.options.webpack.postcss || !nuxt.options.postcss) return false;
|
|
796
|
+
const postcssOptions = defu({}, nuxt.options.postcss, {
|
|
848
797
|
plugins: {
|
|
849
798
|
"postcss-import": { resolve: createResolver({
|
|
850
|
-
alias: { ...nuxt
|
|
851
|
-
modules: nuxt
|
|
799
|
+
alias: { ...nuxt.options.alias },
|
|
800
|
+
modules: nuxt.options.modulesDir
|
|
852
801
|
}) },
|
|
853
802
|
"postcss-url": {}
|
|
854
803
|
},
|
|
855
|
-
sourceMap: nuxt
|
|
804
|
+
sourceMap: nuxt.options.webpack.cssSourceMap
|
|
856
805
|
});
|
|
857
|
-
const jiti = createJiti(nuxt
|
|
806
|
+
const jiti = createJiti(nuxt.options.rootDir, { alias: nuxt.options.alias });
|
|
858
807
|
if (!Array.isArray(postcssOptions.plugins) && isPureObject(postcssOptions.plugins)) {
|
|
859
808
|
const plugins = [];
|
|
860
|
-
for (const pluginName
|
|
861
|
-
const pluginOptions = postcssOptions.plugins[pluginName
|
|
809
|
+
for (const pluginName of sortPlugins(postcssOptions)) {
|
|
810
|
+
const pluginOptions = postcssOptions.plugins[pluginName];
|
|
862
811
|
if (!pluginOptions) continue;
|
|
863
812
|
let pluginFn;
|
|
864
|
-
for (const parentURL of nuxt
|
|
865
|
-
pluginFn = await jiti.import(pluginName
|
|
813
|
+
for (const parentURL of nuxt.options.modulesDir) {
|
|
814
|
+
pluginFn = await jiti.import(pluginName, {
|
|
866
815
|
parentURL: parentURL.replace(/\/node_modules\/?$/, ""),
|
|
867
816
|
try: true,
|
|
868
817
|
default: true
|
|
@@ -872,19 +821,16 @@ async function getPostcssConfig(nuxt$1) {
|
|
|
872
821
|
break;
|
|
873
822
|
}
|
|
874
823
|
}
|
|
875
|
-
if (typeof pluginFn !== "function") console.warn(`[nuxt] could not import postcss plugin \`${pluginName
|
|
824
|
+
if (typeof pluginFn !== "function") console.warn(`[nuxt] could not import postcss plugin \`${pluginName}\`. Please report this as a bug.`);
|
|
876
825
|
}
|
|
877
826
|
postcssOptions.plugins = plugins;
|
|
878
827
|
}
|
|
879
828
|
return {
|
|
880
|
-
sourceMap: nuxt
|
|
881
|
-
...nuxt
|
|
829
|
+
sourceMap: nuxt.options.webpack.cssSourceMap,
|
|
830
|
+
...nuxt.options.webpack.postcss,
|
|
882
831
|
postcssOptions
|
|
883
832
|
};
|
|
884
833
|
}
|
|
885
|
-
|
|
886
|
-
//#endregion
|
|
887
|
-
//#region ../webpack/src/presets/style.ts
|
|
888
834
|
async function style(ctx) {
|
|
889
835
|
await applyPresets(ctx, [
|
|
890
836
|
loaders,
|
|
@@ -964,13 +910,6 @@ async function createPostcssLoadersRule(ctx) {
|
|
|
964
910
|
options: config
|
|
965
911
|
};
|
|
966
912
|
}
|
|
967
|
-
|
|
968
|
-
//#endregion
|
|
969
|
-
//#region ../webpack/src/plugins/vue/client.ts
|
|
970
|
-
/**
|
|
971
|
-
* This file is based on Vue.js (MIT) webpack plugins
|
|
972
|
-
* https://github.com/vuejs/vue/blob/dev/src/server/webpack-plugin/client.js
|
|
973
|
-
*/
|
|
974
913
|
var VueSSRClientPlugin = class {
|
|
975
914
|
serverDist;
|
|
976
915
|
nuxt;
|
|
@@ -988,9 +927,9 @@ var VueSSRClientPlugin = class {
|
|
|
988
927
|
const stats = compilation.getStats().toJson();
|
|
989
928
|
const context = this.nuxt.options.srcDir;
|
|
990
929
|
const initialFiles = /* @__PURE__ */ new Set();
|
|
991
|
-
for (const { assets
|
|
992
|
-
if (!assets
|
|
993
|
-
for (const asset of assets
|
|
930
|
+
for (const { assets } of Object.values(stats.entrypoints)) {
|
|
931
|
+
if (!assets) continue;
|
|
932
|
+
for (const asset of assets) {
|
|
994
933
|
const file = asset.name;
|
|
995
934
|
if ((isJS(file) || isCSS(file)) && !isHotUpdate(file)) initialFiles.add(file);
|
|
996
935
|
}
|
|
@@ -1036,11 +975,11 @@ var VueSSRClientPlugin = class {
|
|
|
1036
975
|
const files = Array.from(filesSet);
|
|
1037
976
|
webpackManifest.modules[relativeId] = files;
|
|
1038
977
|
if (Array.isArray(m.modules)) for (const concatenatedModule of m.modules) {
|
|
1039
|
-
const relativeId
|
|
1040
|
-
webpackManifest.modules[relativeId
|
|
978
|
+
const relativeId = this.getRelativeModuleId(concatenatedModule.identifier, context);
|
|
979
|
+
webpackManifest.modules[relativeId] ||= files;
|
|
1041
980
|
}
|
|
1042
981
|
if (stats.modules) {
|
|
1043
|
-
for (const m
|
|
982
|
+
for (const m of stats.modules) if (m.assets?.length && m.chunks?.includes(cid)) files.push(...m.assets.map(fileToIndex));
|
|
1044
983
|
}
|
|
1045
984
|
}
|
|
1046
985
|
const manifest = normalizeWebpackManifest(webpackManifest);
|
|
@@ -1053,9 +992,6 @@ var VueSSRClientPlugin = class {
|
|
|
1053
992
|
});
|
|
1054
993
|
}
|
|
1055
994
|
};
|
|
1056
|
-
|
|
1057
|
-
//#endregion
|
|
1058
|
-
//#region ../webpack/src/plugins/vue/server.ts
|
|
1059
995
|
const JS_MAP_RE = /\.js\.map$/;
|
|
1060
996
|
var VueSSRServerPlugin = class {
|
|
1061
997
|
options;
|
|
@@ -1068,7 +1004,7 @@ var VueSSRServerPlugin = class {
|
|
|
1068
1004
|
compilation.hooks.processAssets.tapAsync({
|
|
1069
1005
|
name: "VueSSRServerPlugin",
|
|
1070
1006
|
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
1071
|
-
}, (assets
|
|
1007
|
+
}, (assets, cb) => {
|
|
1072
1008
|
const stats = compilation.getStats().toJson();
|
|
1073
1009
|
const [entryName] = Object.keys(stats.entrypoints);
|
|
1074
1010
|
const entryInfo = stats.entrypoints[entryName];
|
|
@@ -1077,24 +1013,24 @@ var VueSSRServerPlugin = class {
|
|
|
1077
1013
|
if (entryAssets.length > 1) throw new Error("Server-side bundle should have one single entry file. Avoid using CommonsChunkPlugin in the server config.");
|
|
1078
1014
|
const [entry] = entryAssets;
|
|
1079
1015
|
if (!entry || typeof entry.name !== "string") throw new Error(`Entry "${entryName}" not found. Did you specify the correct entry option?`);
|
|
1080
|
-
const bundle
|
|
1016
|
+
const bundle = {
|
|
1081
1017
|
entry: entry.name,
|
|
1082
1018
|
files: {},
|
|
1083
1019
|
maps: {}
|
|
1084
1020
|
};
|
|
1085
1021
|
for (const asset of stats.assets) if (isJS(asset.name)) {
|
|
1086
1022
|
const queryPart = extractQueryPartJS(asset.name);
|
|
1087
|
-
if (queryPart !== void 0) bundle
|
|
1088
|
-
else bundle
|
|
1089
|
-
} else if (JS_MAP_RE.test(asset.name)) bundle
|
|
1090
|
-
else delete assets
|
|
1091
|
-
const src = JSON.stringify(bundle
|
|
1092
|
-
assets
|
|
1023
|
+
if (queryPart !== void 0) bundle.files[asset.name] = asset.name.replace(queryPart, "");
|
|
1024
|
+
else bundle.files[asset.name] = asset.name;
|
|
1025
|
+
} else if (JS_MAP_RE.test(asset.name)) bundle.maps[asset.name.replace(/\.map$/, "")] = asset.name;
|
|
1026
|
+
else delete assets[asset.name];
|
|
1027
|
+
const src = JSON.stringify(bundle, null, 2);
|
|
1028
|
+
assets[this.options.filename] = {
|
|
1093
1029
|
source: () => src,
|
|
1094
1030
|
size: () => src.length
|
|
1095
1031
|
};
|
|
1096
1032
|
const mjsSrc = "export default " + src;
|
|
1097
|
-
assets
|
|
1033
|
+
assets[this.options.filename.replace(".json", ".mjs")] = {
|
|
1098
1034
|
source: () => mjsSrc,
|
|
1099
1035
|
map: () => null,
|
|
1100
1036
|
size: () => mjsSrc.length
|
|
@@ -1104,9 +1040,6 @@ var VueSSRServerPlugin = class {
|
|
|
1104
1040
|
});
|
|
1105
1041
|
}
|
|
1106
1042
|
};
|
|
1107
|
-
|
|
1108
|
-
//#endregion
|
|
1109
|
-
//#region ../webpack/src/presets/vue.ts
|
|
1110
1043
|
function vue(ctx) {
|
|
1111
1044
|
ctx.config.plugins.push(new (VueLoaderPlugin.default || VueLoaderPlugin)());
|
|
1112
1045
|
ctx.config.module.rules.push({
|
|
@@ -1136,9 +1069,6 @@ function vue(ctx) {
|
|
|
1136
1069
|
"__VUE_PROD_HYDRATION_MISMATCH_DETAILS__": ctx.nuxt.options.debug && ctx.nuxt.options.debug.hydration
|
|
1137
1070
|
}));
|
|
1138
1071
|
}
|
|
1139
|
-
|
|
1140
|
-
//#endregion
|
|
1141
|
-
//#region ../webpack/src/presets/nuxt.ts
|
|
1142
1072
|
async function nuxt(ctx) {
|
|
1143
1073
|
await applyPresets(ctx, [
|
|
1144
1074
|
base,
|
|
@@ -1149,9 +1079,6 @@ async function nuxt(ctx) {
|
|
|
1149
1079
|
vue
|
|
1150
1080
|
]);
|
|
1151
1081
|
}
|
|
1152
|
-
|
|
1153
|
-
//#endregion
|
|
1154
|
-
//#region ../webpack/src/configs/client.ts
|
|
1155
1082
|
async function client(ctx) {
|
|
1156
1083
|
ctx.name = "client";
|
|
1157
1084
|
ctx.isClient = true;
|
|
@@ -1257,9 +1184,6 @@ function clientPlugins(ctx) {
|
|
|
1257
1184
|
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 }));
|
|
1258
1185
|
}
|
|
1259
1186
|
}
|
|
1260
|
-
|
|
1261
|
-
//#endregion
|
|
1262
|
-
//#region ../webpack/src/presets/node.ts
|
|
1263
1187
|
function node(ctx) {
|
|
1264
1188
|
ctx.config.target = "node";
|
|
1265
1189
|
ctx.config.node = false;
|
|
@@ -1288,9 +1212,6 @@ function node(ctx) {
|
|
|
1288
1212
|
maxAssetSize: Number.POSITIVE_INFINITY
|
|
1289
1213
|
};
|
|
1290
1214
|
}
|
|
1291
|
-
|
|
1292
|
-
//#endregion
|
|
1293
|
-
//#region ../webpack/src/configs/server.ts
|
|
1294
1215
|
const assetPattern = /\.(?:css|s[ca]ss|png|jpe?g|gif|svg|woff2?|eot|ttf|otf|webp|webm|mp4|ogv)(?:\?.*)?$/i;
|
|
1295
1216
|
const VIRTUAL_RE = /^\0?virtual:(?:nuxt:)?/;
|
|
1296
1217
|
async function server(ctx) {
|
|
@@ -1383,117 +1304,117 @@ function serverPlugins(ctx) {
|
|
|
1383
1304
|
}));
|
|
1384
1305
|
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 }));
|
|
1385
1306
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
const webpackConfigs = await Promise.all([client, ...nuxt$1.options.ssr ? [server] : []].map(async (preset) => {
|
|
1391
|
-
const ctx = createWebpackConfigContext(nuxt$1);
|
|
1392
|
-
ctx.userConfig = defu(nuxt$1.options.webpack[`$${preset.name}`], ctx.userConfig);
|
|
1307
|
+
const bundle = async (nuxt) => {
|
|
1308
|
+
const webpackConfigs = await Promise.all([client, ...nuxt.options.ssr ? [server] : []].map(async (preset) => {
|
|
1309
|
+
const ctx = createWebpackConfigContext(nuxt);
|
|
1310
|
+
ctx.userConfig = defu(nuxt.options.webpack[`$${preset.name}`], ctx.userConfig);
|
|
1393
1311
|
await applyPresets(ctx, preset);
|
|
1394
1312
|
return ctx.config;
|
|
1395
1313
|
}));
|
|
1396
|
-
|
|
1397
|
-
if (!nuxt$1.options.dev) useNitro().hooks.hook("rollup:before", (_nitro, config) => {
|
|
1314
|
+
if (!nuxt.options.dev) useNitro().hooks.hook("rollup:before", (_nitro, config) => {
|
|
1398
1315
|
const plugins = config.plugins;
|
|
1399
1316
|
const existingPlugin = plugins.findIndex((i) => i && "name" in i && i.name === "dynamic-require");
|
|
1400
1317
|
if (existingPlugin >= 0) plugins.splice(existingPlugin, 1);
|
|
1401
1318
|
});
|
|
1402
|
-
await nuxt
|
|
1403
|
-
const mfs = nuxt
|
|
1404
|
-
const ssrStylesPlugin = nuxt
|
|
1319
|
+
await nuxt.callHook(`${builder}:config`, webpackConfigs);
|
|
1320
|
+
const mfs = nuxt.options.dev ? createMFS() : null;
|
|
1321
|
+
const ssrStylesPlugin = nuxt.options.ssr && !nuxt.options.dev && nuxt.options.features.inlineStyles ? new SSRStylesPlugin(nuxt) : null;
|
|
1405
1322
|
for (const config of webpackConfigs) {
|
|
1406
|
-
config.plugins.push(DynamicBasePlugin.webpack({ sourcemap: !!nuxt
|
|
1407
|
-
if (config.name === "client" && nuxt
|
|
1323
|
+
config.plugins.push(DynamicBasePlugin.webpack({ sourcemap: !!nuxt.options.sourcemap[config.name] }));
|
|
1324
|
+
if (config.name === "client" && nuxt.options.experimental.emitRouteChunkError && nuxt.options.builder !== "@nuxt/rspack-builder") config.plugins.push(new ChunkErrorPlugin());
|
|
1408
1325
|
if (ssrStylesPlugin) config.plugins.push(ssrStylesPlugin);
|
|
1409
1326
|
}
|
|
1410
|
-
await nuxt
|
|
1327
|
+
await nuxt.callHook(`${builder}:configResolved`, webpackConfigs);
|
|
1411
1328
|
const compilers = webpackConfigs.map((config) => {
|
|
1412
1329
|
const compiler = webpack(config);
|
|
1413
|
-
if (nuxt
|
|
1330
|
+
if (nuxt.options.dev && compiler) compiler.outputFileSystem = mfs;
|
|
1414
1331
|
return compiler;
|
|
1415
1332
|
});
|
|
1416
|
-
nuxt
|
|
1417
|
-
for (const compiler of compilers) await new Promise((resolve
|
|
1333
|
+
nuxt.hook("close", async () => {
|
|
1334
|
+
for (const compiler of compilers) await new Promise((resolve) => compiler.close(resolve));
|
|
1418
1335
|
});
|
|
1419
|
-
if (nuxt
|
|
1336
|
+
if (nuxt.options.dev) {
|
|
1420
1337
|
await Promise.all(compilers.map((c) => compile(c)));
|
|
1421
1338
|
return;
|
|
1422
1339
|
}
|
|
1423
1340
|
for (const c of compilers) await compile(c);
|
|
1424
1341
|
};
|
|
1425
1342
|
async function createDevMiddleware(compiler) {
|
|
1426
|
-
const nuxt
|
|
1343
|
+
const nuxt = useNuxt();
|
|
1427
1344
|
logger.debug("Creating webpack middleware...");
|
|
1428
1345
|
const devMiddleware = webpackDevMiddleware(compiler, {
|
|
1429
|
-
publicPath: joinURL(nuxt
|
|
1346
|
+
publicPath: joinURL(nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir),
|
|
1430
1347
|
outputFileSystem: compiler.outputFileSystem,
|
|
1431
1348
|
stats: "none",
|
|
1432
|
-
...nuxt
|
|
1349
|
+
...nuxt.options.webpack.devMiddleware
|
|
1433
1350
|
});
|
|
1434
|
-
nuxt
|
|
1435
|
-
const { client: _client, ...hotMiddlewareOptions } = nuxt
|
|
1351
|
+
nuxt.hook("close", () => pify(devMiddleware.close.bind(devMiddleware))());
|
|
1352
|
+
const { client: _client, ...hotMiddlewareOptions } = nuxt.options.webpack.hotMiddleware || {};
|
|
1436
1353
|
const hotMiddleware = webpackHotMiddleware(compiler, {
|
|
1437
1354
|
log: false,
|
|
1438
1355
|
heartbeat: 1e4,
|
|
1439
|
-
path: joinURL(nuxt
|
|
1356
|
+
path: joinURL(nuxt.options.app.baseURL, "__webpack_hmr", compiler.options.name),
|
|
1440
1357
|
...hotMiddlewareOptions
|
|
1441
1358
|
});
|
|
1442
1359
|
const devHandler = wdmToH3Handler(devMiddleware);
|
|
1443
|
-
await nuxt
|
|
1360
|
+
await nuxt.callHook("server:devHandler", defineEventHandler(async (event) => {
|
|
1444
1361
|
const body = await devHandler(event);
|
|
1445
1362
|
if (body !== void 0) return body;
|
|
1446
1363
|
const { req, res } = "runtime" in event ? event.runtime.node : event.node;
|
|
1447
|
-
await new Promise((resolve
|
|
1364
|
+
await new Promise((resolve, reject) => hotMiddleware(req, res, (err) => err ? reject(err) : resolve()));
|
|
1448
1365
|
}), { cors: () => true });
|
|
1449
1366
|
return devMiddleware;
|
|
1450
1367
|
}
|
|
1451
1368
|
function wdmToH3Handler(devMiddleware) {
|
|
1452
1369
|
return defineEventHandler(async (event) => {
|
|
1453
1370
|
const { req, res } = "runtime" in event ? event.runtime.node : event.node;
|
|
1454
|
-
if (req.headers["sec-fetch-mode"] === "no-cors" && req.headers["sec-fetch-site"] === "cross-site")
|
|
1371
|
+
if (req.headers["sec-fetch-mode"] === "no-cors" && req.headers["sec-fetch-site"] === "cross-site") {
|
|
1372
|
+
res.statusCode = 403;
|
|
1373
|
+
res.end("Forbidden");
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1455
1376
|
event.context.webpack = {
|
|
1456
1377
|
...event.context.webpack,
|
|
1457
1378
|
devMiddleware: devMiddleware.context
|
|
1458
1379
|
};
|
|
1459
|
-
return await new Promise((resolve
|
|
1380
|
+
return await new Promise((resolve, reject) => {
|
|
1460
1381
|
res.stream = (stream) => {
|
|
1461
|
-
resolve
|
|
1382
|
+
resolve(stream);
|
|
1462
1383
|
};
|
|
1463
1384
|
res.send = (data) => {
|
|
1464
|
-
resolve
|
|
1385
|
+
resolve(data);
|
|
1465
1386
|
};
|
|
1466
1387
|
res.finish = (data) => {
|
|
1467
|
-
resolve
|
|
1388
|
+
resolve(data);
|
|
1468
1389
|
};
|
|
1469
1390
|
devMiddleware(req, res, (err) => {
|
|
1470
1391
|
if (err) reject(err);
|
|
1471
|
-
else resolve
|
|
1392
|
+
else resolve(void 0);
|
|
1472
1393
|
});
|
|
1473
1394
|
});
|
|
1474
1395
|
});
|
|
1475
1396
|
}
|
|
1476
1397
|
async function compile(compiler) {
|
|
1477
|
-
const nuxt
|
|
1478
|
-
await nuxt
|
|
1398
|
+
const nuxt = useNuxt();
|
|
1399
|
+
await nuxt.callHook(`${builder}:compile`, {
|
|
1479
1400
|
name: compiler.options.name,
|
|
1480
1401
|
compiler
|
|
1481
1402
|
});
|
|
1482
|
-
compiler.hooks.done.tap("load-resources", async (stats
|
|
1483
|
-
await nuxt
|
|
1403
|
+
compiler.hooks.done.tap("load-resources", async (stats) => {
|
|
1404
|
+
await nuxt.callHook(`${builder}:compiled`, {
|
|
1484
1405
|
name: compiler.options.name,
|
|
1485
1406
|
compiler,
|
|
1486
|
-
stats
|
|
1407
|
+
stats
|
|
1487
1408
|
});
|
|
1488
1409
|
});
|
|
1489
|
-
if (nuxt
|
|
1410
|
+
if (nuxt.options.dev) {
|
|
1490
1411
|
const compilersWatching = [];
|
|
1491
|
-
nuxt
|
|
1412
|
+
nuxt.hook("close", async () => {
|
|
1492
1413
|
await Promise.all(compilersWatching.map((watching) => watching && pify(watching.close.bind(watching))()));
|
|
1493
1414
|
});
|
|
1494
|
-
if (compiler.options.name === "client") return new Promise((resolve
|
|
1415
|
+
if (compiler.options.name === "client") return new Promise((resolve, reject) => {
|
|
1495
1416
|
compiler.hooks.done.tap("nuxt-dev", () => {
|
|
1496
|
-
resolve
|
|
1417
|
+
resolve(null);
|
|
1497
1418
|
});
|
|
1498
1419
|
compiler.hooks.failed.tap("nuxt-errorlog", (err) => {
|
|
1499
1420
|
reject(err);
|
|
@@ -1502,15 +1423,15 @@ async function compile(compiler) {
|
|
|
1502
1423
|
if (devMiddleware.context.watching) compilersWatching.push(devMiddleware.context.watching);
|
|
1503
1424
|
});
|
|
1504
1425
|
});
|
|
1505
|
-
return new Promise((resolve
|
|
1506
|
-
const watching = compiler.watch(nuxt
|
|
1426
|
+
return new Promise((resolve, reject) => {
|
|
1427
|
+
const watching = compiler.watch(nuxt.options.watchers.webpack, (err) => {
|
|
1507
1428
|
if (err) return reject(err);
|
|
1508
|
-
resolve
|
|
1429
|
+
resolve(null);
|
|
1509
1430
|
});
|
|
1510
1431
|
compilersWatching.push(watching);
|
|
1511
1432
|
});
|
|
1512
1433
|
}
|
|
1513
|
-
const stats = await new Promise((resolve
|
|
1434
|
+
const stats = await new Promise((resolve, reject) => compiler.run((err, stats) => err ? reject(err) : resolve(stats)));
|
|
1514
1435
|
if (stats.hasErrors()) {
|
|
1515
1436
|
const error = /* @__PURE__ */ new Error("Nuxt build error");
|
|
1516
1437
|
error.stack = stats.toString("errors-only");
|
|
@@ -1520,6 +1441,4 @@ async function compile(compiler) {
|
|
|
1520
1441
|
function defineEventHandler(handler) {
|
|
1521
1442
|
return Object.assign(handler, { __is_handler__: true });
|
|
1522
1443
|
}
|
|
1523
|
-
|
|
1524
|
-
//#endregion
|
|
1525
|
-
export { bundle };
|
|
1444
|
+
export { bundle };
|