@nuxt/webpack-builder 4.2.1 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/dist/index.d.mts +5 -4
- package/dist/index.mjs +1383 -1143
- package/dist/loaders/vue-module-identifier.mjs +16 -0
- package/package.json +31 -27
- package/dist/index.d.ts +0 -5
package/dist/index.mjs
CHANGED
|
@@ -1,193 +1,534 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import webpackDevMiddleware from
|
|
4
|
-
import webpackHotMiddleware from
|
|
5
|
-
import { defu } from
|
|
6
|
-
import { joinURL } from
|
|
7
|
-
import { logger, useNitro, useNuxt } from
|
|
8
|
-
import { createUnplugin } from
|
|
9
|
-
import MagicString from
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import pify from "pify";
|
|
3
|
+
import webpackDevMiddleware from "webpack-dev-middleware";
|
|
4
|
+
import webpackHotMiddleware from "webpack-hot-middleware";
|
|
5
|
+
import { defu } from "defu";
|
|
6
|
+
import { joinURL, parseURL, withTrailingSlash } from "ufo";
|
|
7
|
+
import { directoryToURL, logger, resolveAlias, useNitro, useNuxt } from "@nuxt/kit";
|
|
8
|
+
import { createUnplugin } from "unplugin";
|
|
9
|
+
import MagicString from "magic-string";
|
|
10
|
+
import webpack from "webpack";
|
|
11
|
+
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
12
|
+
import WebpackBarPlugin from "webpackbar";
|
|
13
|
+
import TsCheckerPlugin from "fork-ts-checker-webpack-plugin";
|
|
14
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
15
|
+
import { pathToFileURL } from "node:url";
|
|
16
|
+
import { basename, isAbsolute, join, normalize, relative, resolve } from "pathe";
|
|
17
|
+
import { genArrayFromRaw, genObjectFromRawEntries, genString } from "knitwork";
|
|
18
|
+
import { compileStyle, parse } from "@vue/compiler-sfc";
|
|
19
|
+
import { createHash } from "node:crypto";
|
|
20
|
+
import { Volume, createFsFromVolume } from "memfs";
|
|
21
|
+
import querystring from "node:querystring";
|
|
22
|
+
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
|
|
23
|
+
import { defineEnv } from "unenv";
|
|
24
|
+
import TimeFixPlugin from "time-fix-plugin";
|
|
25
|
+
import FriendlyErrorsWebpackPlugin from "@nuxt/friendly-errors-webpack-plugin";
|
|
26
|
+
import escapeRegExp from "escape-string-regexp";
|
|
27
|
+
import { isTest } from "std-env";
|
|
28
|
+
import { EsbuildPlugin } from "esbuild-loader";
|
|
29
|
+
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
|
|
30
|
+
import createResolver from "postcss-import-resolver";
|
|
31
|
+
import { createJiti } from "jiti";
|
|
32
|
+
import VueLoaderPlugin from "vue-loader/dist/pluginWebpack5.js";
|
|
33
|
+
import { resolveModulePath } from "exsolve";
|
|
34
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
35
|
+
import { normalizeWebpackManifest, precomputeDependencies } from "vue-bundle-renderer";
|
|
36
|
+
import { hash } from "ohash";
|
|
37
|
+
import { serialize } from "seroval";
|
|
38
|
+
import { parseNodeModulePath } from "mlly";
|
|
30
39
|
|
|
40
|
+
//#region src/plugins/dynamic-base.ts
|
|
31
41
|
const defaults = {
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
globalPublicPath: "__webpack_public_path__",
|
|
43
|
+
sourcemap: true
|
|
34
44
|
};
|
|
35
45
|
const ENTRY_RE = /import ["']#build\/css["'];/;
|
|
36
46
|
const DynamicBasePlugin = createUnplugin((options = {}) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
options = {
|
|
48
|
+
...defaults,
|
|
49
|
+
...options
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
name: "nuxt:dynamic-base-path",
|
|
53
|
+
enforce: "post",
|
|
54
|
+
transform: {
|
|
55
|
+
filter: {
|
|
56
|
+
id: { include: /entry/ },
|
|
57
|
+
code: { include: ENTRY_RE }
|
|
58
|
+
},
|
|
59
|
+
handler(code) {
|
|
60
|
+
const s = new MagicString(code);
|
|
61
|
+
s.prepend(`import { buildAssetsURL } from '#internal/nuxt/paths';\n${options.globalPublicPath} = buildAssetsURL();\n`);
|
|
62
|
+
return {
|
|
63
|
+
code: s.toString(),
|
|
64
|
+
map: options.sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
58
69
|
});
|
|
59
70
|
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region builder.mjs
|
|
73
|
+
const builder = "webpack";
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/plugins/chunk.ts
|
|
60
77
|
const pluginName = "ChunkErrorPlugin";
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
var ChunkErrorPlugin = class {
|
|
79
|
+
apply(compiler) {
|
|
80
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
|
|
81
|
+
compilation.hooks.runtimeRequirementInTree.for(webpack.RuntimeGlobals.ensureChunk).tap(pluginName, (chunk) => {
|
|
82
|
+
compilation.addRuntimeModule(chunk, new ChunkErrorRuntimeModule());
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var ChunkErrorRuntimeModule = class extends webpack.RuntimeModule {
|
|
88
|
+
constructor() {
|
|
89
|
+
super("chunk preload error handler", webpack.RuntimeModule.STAGE_ATTACH);
|
|
90
|
+
}
|
|
91
|
+
generate() {
|
|
92
|
+
const { ensureChunk } = webpack.RuntimeGlobals;
|
|
93
|
+
return `
|
|
94
|
+
if (typeof ${ensureChunk} !== "undefined") {
|
|
95
|
+
var _ensureChunk = ${ensureChunk};
|
|
96
|
+
${ensureChunk} = function (chunkId) {
|
|
97
|
+
return Promise.resolve(_ensureChunk(chunkId)).catch(function(error) {
|
|
98
|
+
var e = new Event('nuxt:preloadError', { cancelable: true });
|
|
99
|
+
e.payload = error;
|
|
100
|
+
window.dispatchEvent(e);
|
|
101
|
+
throw error;
|
|
71
102
|
});
|
|
72
103
|
};
|
|
73
|
-
};`;
|
|
74
|
-
apply(compiler) {
|
|
75
|
-
compiler.hooks.thisCompilation.tap(
|
|
76
|
-
pluginName,
|
|
77
|
-
(compilation) => compilation.mainTemplate.hooks.localVars.tap(
|
|
78
|
-
{ name: pluginName, stage: 1 },
|
|
79
|
-
(source) => source + this.script
|
|
80
|
-
)
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
104
|
}
|
|
105
|
+
`;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/plugins/ssr-styles.ts
|
|
111
|
+
const CSS_URL_RE = /url\((['"]?)(\/[^)]+?)\1\)/g;
|
|
112
|
+
const isVueFile = (id) => /\.vue(?:\?|$)/.test(id);
|
|
113
|
+
const isCSSLike = (name) => /\.(?:css|scss|sass|less|styl(?:us)?|postcss|pcss)(?:\?|$)/.test(name);
|
|
114
|
+
function normalizePath(nuxt$1, id) {
|
|
115
|
+
if (!id) return null;
|
|
116
|
+
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
117
|
+
const rel = relative(nuxt$1.options.srcDir, pathname);
|
|
118
|
+
if (rel.startsWith("..")) return null;
|
|
119
|
+
return rel;
|
|
120
|
+
}
|
|
121
|
+
function resolveFilePath(id) {
|
|
122
|
+
if (!id) return null;
|
|
123
|
+
return parseURL(decodeURIComponent(pathToFileURL(id).href)).pathname || null;
|
|
124
|
+
}
|
|
125
|
+
function sanitizeStyleAssetName(rel) {
|
|
126
|
+
return rel.replace(/[\\/]/g, "_").replace(/\.{2,}/g, "_");
|
|
127
|
+
}
|
|
128
|
+
function normalizeCSSContent(css) {
|
|
129
|
+
return css.trim().replace(/(--[^:]+):\s*'([^']*)'/g, "$1:\"$2\"").replace(/:\s+/g, ":").replace(/\s*\{\s*/g, "{").replace(/;\s*\}/g, "}").replace(/\s*\}\s*/g, "}");
|
|
130
|
+
}
|
|
131
|
+
function extractVueStyles(filePath) {
|
|
132
|
+
try {
|
|
133
|
+
const { descriptor } = parse(readFileSync(filePath, "utf8"), { filename: filePath });
|
|
134
|
+
const styles = [];
|
|
135
|
+
const scopeId = createHash("sha256").update(filePath).digest("hex").slice(0, 8);
|
|
136
|
+
for (let i = 0; i < descriptor.styles.length; i++) {
|
|
137
|
+
const style$1 = descriptor.styles[i];
|
|
138
|
+
const result = compileStyle({
|
|
139
|
+
source: style$1.content,
|
|
140
|
+
filename: filePath,
|
|
141
|
+
id: `data-v-${scopeId}`,
|
|
142
|
+
scoped: style$1.scoped
|
|
143
|
+
});
|
|
144
|
+
if (!result.errors.length && result.code) styles.push(normalizeCSSContent(result.code));
|
|
145
|
+
}
|
|
146
|
+
return styles;
|
|
147
|
+
} catch {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
var SSRStylesPlugin = class {
|
|
152
|
+
nuxt;
|
|
153
|
+
clientCSSByIssuer = /* @__PURE__ */ new Map();
|
|
154
|
+
chunksWithInlinedCSS = /* @__PURE__ */ new Set();
|
|
155
|
+
globalCSSPaths = /* @__PURE__ */ new Set();
|
|
156
|
+
constructor(nuxt$1) {
|
|
157
|
+
this.nuxt = nuxt$1;
|
|
158
|
+
this.globalCSSPaths = this.resolveGlobalCSS();
|
|
159
|
+
nuxt$1.hook("build:manifest", (manifest) => {
|
|
160
|
+
for (const [id, chunk] of Object.entries(manifest)) {
|
|
161
|
+
if (chunk.isEntry && chunk.src) this.chunksWithInlinedCSS.add(chunk.src);
|
|
162
|
+
else if (this.chunksWithInlinedCSS.has(id)) chunk.css &&= [];
|
|
163
|
+
if (chunk.css?.length) chunk.css = chunk.css.filter((cssPath) => {
|
|
164
|
+
for (const globalPath of this.globalCSSPaths) if (cssPath.includes(globalPath.split("/").pop() || "")) return false;
|
|
165
|
+
return true;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
shouldInline(mod) {
|
|
171
|
+
const shouldInline = this.nuxt.options.features.inlineStyles;
|
|
172
|
+
if (typeof shouldInline === "boolean") return shouldInline;
|
|
173
|
+
return shouldInline(mod.identifier());
|
|
174
|
+
}
|
|
175
|
+
escapeTemplateLiteral(str) {
|
|
176
|
+
return str.replace(/[`\\$]/g, (m) => m === "$" ? "\\$" : `\\${m}`);
|
|
177
|
+
}
|
|
178
|
+
isBuildAsset(url) {
|
|
179
|
+
const buildDir = withTrailingSlash(this.nuxt.options.app.buildAssetsDir || "/_nuxt/");
|
|
180
|
+
return url.startsWith(buildDir);
|
|
181
|
+
}
|
|
182
|
+
isPublicAsset(url, nitro) {
|
|
183
|
+
const cleaned = url.replace(/[?#].*$/, "");
|
|
184
|
+
for (const dir of nitro.options.publicAssets) {
|
|
185
|
+
const base$1 = withTrailingSlash(dir.baseURL || "/");
|
|
186
|
+
if (!url.startsWith(base$1)) continue;
|
|
187
|
+
if (existsSync(cleaned.replace(base$1, withTrailingSlash(dir.dir)))) return true;
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
rewriteStyle(css, nitro) {
|
|
192
|
+
let changed = false;
|
|
193
|
+
let needsPublicAsset = false;
|
|
194
|
+
let needsBuildAsset = false;
|
|
195
|
+
let lastIndex = 0;
|
|
196
|
+
let out = "`";
|
|
197
|
+
for (const match of css.matchAll(CSS_URL_RE)) {
|
|
198
|
+
const index = match.index ?? 0;
|
|
199
|
+
const before = css.slice(lastIndex, index);
|
|
200
|
+
if (before) out += this.escapeTemplateLiteral(before);
|
|
201
|
+
const full = match[0];
|
|
202
|
+
const rawUrl = match[2] || "";
|
|
203
|
+
const stripped = rawUrl.replace(/[?#].*$/, "");
|
|
204
|
+
if (this.isPublicAsset(stripped, nitro)) {
|
|
205
|
+
needsPublicAsset = true;
|
|
206
|
+
changed = true;
|
|
207
|
+
out += "${publicAssetsURL(" + JSON.stringify(rawUrl) + ")}";
|
|
208
|
+
} else if (this.isBuildAsset(stripped)) {
|
|
209
|
+
needsBuildAsset = true;
|
|
210
|
+
changed = true;
|
|
211
|
+
out += "${buildAssetsURL(" + JSON.stringify(rawUrl) + ")}";
|
|
212
|
+
} else out += this.escapeTemplateLiteral(full);
|
|
213
|
+
lastIndex = index + full.length;
|
|
214
|
+
}
|
|
215
|
+
const tail = css.slice(lastIndex);
|
|
216
|
+
if (tail) out += this.escapeTemplateLiteral(tail);
|
|
217
|
+
out += "`";
|
|
218
|
+
return {
|
|
219
|
+
code: changed ? out : JSON.stringify(css),
|
|
220
|
+
needsPublicAsset,
|
|
221
|
+
needsBuildAsset
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
resolveGlobalCSS() {
|
|
225
|
+
const req = createRequire(this.nuxt.options.rootDir);
|
|
226
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
227
|
+
const entries = this.nuxt.options.css || [];
|
|
228
|
+
for (const entry of entries) {
|
|
229
|
+
const src = typeof entry === "string" ? entry : entry?.src;
|
|
230
|
+
if (!src) continue;
|
|
231
|
+
const path = this.resolveCSSRequest(src, req);
|
|
232
|
+
if (path) resolved.add(path);
|
|
233
|
+
}
|
|
234
|
+
return resolved;
|
|
235
|
+
}
|
|
236
|
+
resolveCSSRequest(request, req) {
|
|
237
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
238
|
+
const resolved = resolveAlias(request, this.nuxt.options.alias);
|
|
239
|
+
if (isAbsolute(resolved)) candidates.add(resolved);
|
|
240
|
+
else candidates.add(resolve(this.nuxt.options.srcDir, resolved));
|
|
241
|
+
try {
|
|
242
|
+
candidates.add(req.resolve(request));
|
|
243
|
+
} catch {}
|
|
244
|
+
for (const candidate of candidates) {
|
|
245
|
+
const path = resolveFilePath(candidate);
|
|
246
|
+
if (path) return path;
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
normalizeResourcePath(resource) {
|
|
251
|
+
if (!resource) return null;
|
|
252
|
+
const withoutQuery = resource.split("?")[0];
|
|
253
|
+
return resolveFilePath(withoutQuery);
|
|
254
|
+
}
|
|
255
|
+
apply(compiler) {
|
|
256
|
+
if (this.nuxt.options.dev) return;
|
|
257
|
+
const isClient = compiler.options.name === "client";
|
|
258
|
+
const isServer = compiler.options.name === "server";
|
|
259
|
+
if (!isClient && !isServer) return;
|
|
260
|
+
compiler.hooks.thisCompilation.tap("SSRStylesPlugin", (compilation) => {
|
|
261
|
+
this.collectCSS(compilation);
|
|
262
|
+
if (isClient) this.removeGlobalCSSFromClient(compilation);
|
|
263
|
+
if (isServer) this.emitServerStyles(compilation);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
emitServerStyles(compilation) {
|
|
267
|
+
const { webpack: webpack$1 } = compilation.compiler;
|
|
268
|
+
const stage = webpack$1.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE;
|
|
269
|
+
compilation.hooks.processAssets.tap({
|
|
270
|
+
name: "SSRStylesPlugin",
|
|
271
|
+
stage
|
|
272
|
+
}, () => {
|
|
273
|
+
const nitro = useNitro();
|
|
274
|
+
const collected = new Map(this.clientCSSByIssuer);
|
|
275
|
+
const entryModules = /* @__PURE__ */ new Set();
|
|
276
|
+
for (const entrypoint of compilation.entrypoints.values()) {
|
|
277
|
+
const primaryChunk = typeof entrypoint.getEntrypointChunk === "function" ? entrypoint.getEntrypointChunk() : void 0;
|
|
278
|
+
const chunks = primaryChunk ? [primaryChunk] : entrypoint.chunks;
|
|
279
|
+
for (const chunk of chunks) for (const mod of compilation.chunkGraph.getChunkModulesIterable(chunk)) if ("resource" in mod && typeof mod.resource === "string") {
|
|
280
|
+
const resolved = resolveFilePath(mod.resource);
|
|
281
|
+
if (resolved) {
|
|
282
|
+
const rel = normalizePath(this.nuxt, resolved);
|
|
283
|
+
if (rel) entryModules.add(rel);
|
|
284
|
+
else entryModules.add(resolved);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
for (const module of compilation.modules) {
|
|
289
|
+
const resource = module.resource;
|
|
290
|
+
if (!resource || !isVueFile(resource)) continue;
|
|
291
|
+
const rel = normalizePath(this.nuxt, resource);
|
|
292
|
+
if (!rel) continue;
|
|
293
|
+
if (collected.has(rel)) continue;
|
|
294
|
+
const vueStyles = extractVueStyles(resolveFilePath(resource) || resource);
|
|
295
|
+
if (vueStyles.length) collected.set(rel, new Set(vueStyles));
|
|
296
|
+
}
|
|
297
|
+
const emitted = {};
|
|
298
|
+
const rawSource = webpack$1.sources.RawSource;
|
|
299
|
+
for (const [rel, cssSet] of collected.entries()) {
|
|
300
|
+
if (!cssSet.size) continue;
|
|
301
|
+
const transformed = Array.from(cssSet).map((style$1) => this.rewriteStyle(style$1, nitro));
|
|
302
|
+
const needsPublicAssets = transformed.some((t) => t.needsPublicAsset);
|
|
303
|
+
const needsBuildAssets = transformed.some((t) => t.needsBuildAsset);
|
|
304
|
+
const imports = [];
|
|
305
|
+
if (needsPublicAssets || needsBuildAssets) {
|
|
306
|
+
const names = [];
|
|
307
|
+
if (needsBuildAssets) names.push("buildAssetsURL");
|
|
308
|
+
if (needsPublicAssets) names.push("publicAssetsURL");
|
|
309
|
+
imports.push(`import { ${names.join(", ")} } from '#internal/nuxt/paths'`);
|
|
310
|
+
}
|
|
311
|
+
const moduleSource = [...imports, `export default ${genArrayFromRaw(transformed.map((t) => t.code))}`].filter(Boolean).join("\n");
|
|
312
|
+
const styleModuleName = `${sanitizeStyleAssetName(rel)}-styles.mjs`;
|
|
313
|
+
compilation.emitAsset(styleModuleName, new rawSource(moduleSource));
|
|
314
|
+
emitted[rel] = styleModuleName;
|
|
315
|
+
this.chunksWithInlinedCSS.add(rel);
|
|
316
|
+
}
|
|
317
|
+
const stylesSource = ["const interopDefault = r => r.default || r || []", `export default ${genObjectFromRawEntries(Object.entries(emitted).map(([key, value]) => [key, `() => import('./${value}').then(interopDefault)`]))}`].join("\n");
|
|
318
|
+
compilation.emitAsset("styles.mjs", new rawSource(stylesSource));
|
|
319
|
+
const entryIds = Array.from(this.chunksWithInlinedCSS).filter((id) => entryModules.has(id));
|
|
320
|
+
nitro.options.virtual["#internal/nuxt/entry-ids.mjs"] = () => `export default ${JSON.stringify(entryIds)}`;
|
|
321
|
+
nitro.options._config.virtual ||= {};
|
|
322
|
+
nitro.options._config.virtual["#internal/nuxt/entry-ids.mjs"] = nitro.options.virtual["#internal/nuxt/entry-ids.mjs"];
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
findIssuerPath(compilation, mod) {
|
|
326
|
+
let issuer = compilation.moduleGraph.getIssuer(mod);
|
|
327
|
+
while (issuer) {
|
|
328
|
+
if ("resource" in issuer && typeof issuer.resource === "string") return issuer.resource;
|
|
329
|
+
issuer = compilation.moduleGraph.getIssuer(issuer);
|
|
330
|
+
}
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
removeGlobalCSSFromClient(compilation) {
|
|
334
|
+
compilation.hooks.processAssets.tap({
|
|
335
|
+
name: "SSRStylesPlugin:RemoveGlobalCSS",
|
|
336
|
+
stage: 650
|
|
337
|
+
}, () => {
|
|
338
|
+
for (const chunk of compilation.chunks) if (chunk.name === "nuxt-global-css") {
|
|
339
|
+
const cssAssets = [];
|
|
340
|
+
for (const file of Array.from(chunk.files)) {
|
|
341
|
+
const filename = String(file);
|
|
342
|
+
if (isCSSLike(filename)) {
|
|
343
|
+
const source = compilation.getAsset(filename)?.source;
|
|
344
|
+
const content = source && typeof source.source === "function" ? source.source() : null;
|
|
345
|
+
const text = typeof content === "string" ? content : content instanceof Buffer ? content.toString("utf8") : "";
|
|
346
|
+
if (text) cssAssets.push(text);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (cssAssets.length > 0) for (const mod of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
|
|
350
|
+
const issuerPath = this.findIssuerPath(compilation, mod) || ("resource" in mod && typeof mod.resource === "string" ? mod.resource : null);
|
|
351
|
+
const normalized = normalizePath(this.nuxt, issuerPath);
|
|
352
|
+
if (!normalized) continue;
|
|
353
|
+
const set = this.clientCSSByIssuer.get(normalized) || /* @__PURE__ */ new Set();
|
|
354
|
+
for (const css of cssAssets) set.add(normalizeCSSContent(css));
|
|
355
|
+
this.clientCSSByIssuer.set(normalized, set);
|
|
356
|
+
}
|
|
357
|
+
for (const file of Array.from(chunk.files)) {
|
|
358
|
+
const filename = String(file);
|
|
359
|
+
if (isCSSLike(filename)) {
|
|
360
|
+
compilation.deleteAsset(filename);
|
|
361
|
+
chunk.files.delete(file);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
collectCSS(compilation) {
|
|
368
|
+
const { webpack: webpack$1 } = compilation.compiler;
|
|
369
|
+
const stage = compilation.compiler.options.name === "server" ? webpack$1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS : webpack$1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER;
|
|
370
|
+
const chunkCSSMeta = /* @__PURE__ */ new Map();
|
|
371
|
+
compilation.hooks.processAssets.tap({
|
|
372
|
+
name: "SSRStylesPlugin",
|
|
373
|
+
stage
|
|
374
|
+
}, () => {
|
|
375
|
+
const cssAssetsByChunk = /* @__PURE__ */ new Map();
|
|
376
|
+
for (const chunk of compilation.chunks) {
|
|
377
|
+
const cssAssets = [];
|
|
378
|
+
const chunkCSSFiles = [];
|
|
379
|
+
for (const file of chunk.files) {
|
|
380
|
+
if (!isCSSLike(file)) continue;
|
|
381
|
+
chunkCSSFiles.push(file);
|
|
382
|
+
const source = compilation.getAsset(file)?.source;
|
|
383
|
+
const content = source && typeof source.source === "function" ? source.source() : null;
|
|
384
|
+
const text = typeof content === "string" ? content : content instanceof Buffer ? content.toString("utf8") : "";
|
|
385
|
+
if (text) cssAssets.push(text);
|
|
386
|
+
}
|
|
387
|
+
if (chunkCSSFiles.length) {
|
|
388
|
+
const chunkCSSModules = Array.from(compilation.chunkGraph.getChunkModulesIterable(chunk));
|
|
389
|
+
chunkCSSMeta.set(chunk, {
|
|
390
|
+
files: chunkCSSFiles,
|
|
391
|
+
modules: chunkCSSModules
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
if (cssAssets.length) cssAssetsByChunk.set(chunk, cssAssets);
|
|
395
|
+
}
|
|
396
|
+
for (const [chunk, cssAssets] of cssAssetsByChunk) for (const mod of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
|
|
397
|
+
if (!this.shouldInline(mod)) continue;
|
|
398
|
+
const issuerPath = this.findIssuerPath(compilation, mod) || ("resource" in mod && typeof mod.resource === "string" ? mod.resource : null);
|
|
399
|
+
const normalized = normalizePath(this.nuxt, issuerPath);
|
|
400
|
+
if (!normalized) continue;
|
|
401
|
+
const set = this.clientCSSByIssuer.get(normalized) || /* @__PURE__ */ new Set();
|
|
402
|
+
for (const css of cssAssets) set.add(normalizeCSSContent(css));
|
|
403
|
+
this.clientCSSByIssuer.set(normalized, set);
|
|
404
|
+
}
|
|
405
|
+
for (const mod of compilation.modules) {
|
|
406
|
+
if (!this.shouldInline(mod)) continue;
|
|
407
|
+
const issuerPath = this.findIssuerPath(compilation, mod);
|
|
408
|
+
const normalized = normalizePath(this.nuxt, issuerPath);
|
|
409
|
+
if (!normalized) continue;
|
|
410
|
+
const cssChunks = this.getModuleCSS(mod, compilation);
|
|
411
|
+
if (!cssChunks.length) continue;
|
|
412
|
+
const set = this.clientCSSByIssuer.get(normalized) || /* @__PURE__ */ new Set();
|
|
413
|
+
set.add(cssChunks.join("\n"));
|
|
414
|
+
this.clientCSSByIssuer.set(normalized, set);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
getModuleCSS(mod, _compilation) {
|
|
419
|
+
const cssModule = mod;
|
|
420
|
+
const cssChunks = [];
|
|
421
|
+
if (mod.type === "css/mini-extract" && Array.isArray(cssModule.content)) for (const part of cssModule.content) {
|
|
422
|
+
const css = part?.[1];
|
|
423
|
+
if (css && typeof css === "string") cssChunks.push(normalizeCSSContent(css));
|
|
424
|
+
}
|
|
425
|
+
return cssChunks;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
84
428
|
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/utils/mfs.ts
|
|
85
431
|
function createMFS() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return _fs;
|
|
432
|
+
const _fs = { ...createFsFromVolume(new Volume()) };
|
|
433
|
+
_fs.join = join;
|
|
434
|
+
_fs.exists = (p) => Promise.resolve(_fs.existsSync(p));
|
|
435
|
+
_fs.readFile = pify(_fs.readFile);
|
|
436
|
+
return _fs;
|
|
92
437
|
}
|
|
93
438
|
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region src/utils/index.ts
|
|
441
|
+
/** @since 3.9.0 */
|
|
94
442
|
function toArray(value) {
|
|
95
|
-
|
|
443
|
+
return Array.isArray(value) ? value : [value];
|
|
96
444
|
}
|
|
97
445
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region src/utils/config.ts
|
|
448
|
+
function createWebpackConfigContext(nuxt$1) {
|
|
449
|
+
return {
|
|
450
|
+
nuxt: nuxt$1,
|
|
451
|
+
options: nuxt$1.options,
|
|
452
|
+
userConfig: nuxt$1.options.webpack,
|
|
453
|
+
config: {},
|
|
454
|
+
name: "base",
|
|
455
|
+
isDev: nuxt$1.options.dev,
|
|
456
|
+
isServer: false,
|
|
457
|
+
isClient: false,
|
|
458
|
+
alias: {},
|
|
459
|
+
transpile: []
|
|
460
|
+
};
|
|
111
461
|
}
|
|
112
462
|
async function applyPresets(ctx, presets) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
await preset[0](ctx, preset[1]);
|
|
116
|
-
} else {
|
|
117
|
-
await preset(ctx);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
463
|
+
for (const preset of toArray(presets)) if (Array.isArray(preset)) await preset[0](ctx, preset[1]);
|
|
464
|
+
else await preset(ctx);
|
|
120
465
|
}
|
|
121
466
|
function fileName(ctx, key) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
logger.warn(`Notice: Please do not use ${hash[1]} in dev mode to prevent memory leak`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return fileName2;
|
|
467
|
+
let fileName$1 = ctx.userConfig.filenames[key];
|
|
468
|
+
if (typeof fileName$1 === "function") fileName$1 = fileName$1(ctx);
|
|
469
|
+
if (typeof fileName$1 === "string" && ctx.options.dev) {
|
|
470
|
+
const hash$1 = /\[(chunkhash|contenthash|hash)(?::\d+)?\]/.exec(fileName$1);
|
|
471
|
+
if (hash$1) logger.warn(`Notice: Please do not use ${hash$1[1]} in dev mode to prevent memory leak`);
|
|
472
|
+
}
|
|
473
|
+
return fileName$1;
|
|
133
474
|
}
|
|
134
475
|
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/presets/assets.ts
|
|
135
478
|
function assets(ctx) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
}]
|
|
166
|
-
}
|
|
167
|
-
);
|
|
479
|
+
ctx.config.module.rules.push({
|
|
480
|
+
test: /\.(png|jpe?g|gif|svg|webp)$/i,
|
|
481
|
+
use: [{
|
|
482
|
+
loader: "url-loader",
|
|
483
|
+
options: {
|
|
484
|
+
...ctx.userConfig.loaders.imgUrl,
|
|
485
|
+
name: fileName(ctx, "img")
|
|
486
|
+
}
|
|
487
|
+
}]
|
|
488
|
+
}, {
|
|
489
|
+
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
|
|
490
|
+
use: [{
|
|
491
|
+
loader: "url-loader",
|
|
492
|
+
options: {
|
|
493
|
+
...ctx.userConfig.loaders.fontUrl,
|
|
494
|
+
name: fileName(ctx, "font")
|
|
495
|
+
}
|
|
496
|
+
}]
|
|
497
|
+
}, {
|
|
498
|
+
test: /\.(webm|mp4|ogv)$/i,
|
|
499
|
+
use: [{
|
|
500
|
+
loader: "file-loader",
|
|
501
|
+
options: {
|
|
502
|
+
...ctx.userConfig.loaders.file,
|
|
503
|
+
name: fileName(ctx, "video")
|
|
504
|
+
}
|
|
505
|
+
}]
|
|
506
|
+
});
|
|
168
507
|
}
|
|
169
508
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
509
|
+
//#endregion
|
|
510
|
+
//#region src/plugins/warning-ignore.ts
|
|
511
|
+
var WarningIgnorePlugin = class {
|
|
512
|
+
filter;
|
|
513
|
+
constructor(filter) {
|
|
514
|
+
this.filter = filter;
|
|
515
|
+
}
|
|
516
|
+
apply(compiler) {
|
|
517
|
+
compiler.hooks.done.tap("warnfix-plugin", (stats) => {
|
|
518
|
+
stats.compilation.warnings = stats.compilation.warnings.filter(this.filter);
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
};
|
|
181
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
|
+
*/
|
|
182
529
|
const validate = (compiler) => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
if (!compiler.options.externals) {
|
|
187
|
-
logger.info(
|
|
188
|
-
"It is recommended to externalize dependencies in the server build for better build performance."
|
|
189
|
-
);
|
|
190
|
-
}
|
|
530
|
+
if (compiler.options.target !== "node") logger.warn("webpack config `target` should be \"node\".");
|
|
531
|
+
if (!compiler.options.externals) logger.info("It is recommended to externalize dependencies in the server build for better build performance.");
|
|
191
532
|
};
|
|
192
533
|
const isJSRegExp = /\.[cm]?js(\?[^.]+)?$/;
|
|
193
534
|
const isJS = (file) => isJSRegExp.test(file);
|
|
@@ -196,87 +537,66 @@ const isCSSRegExp = /\.css(?:\?[^.]+)?$/;
|
|
|
196
537
|
const isCSS = (file) => isCSSRegExp.test(file);
|
|
197
538
|
const isHotUpdate = (file) => file.includes("hot-update");
|
|
198
539
|
|
|
540
|
+
//#endregion
|
|
541
|
+
//#region src/plugins/rollup-compat-dynamic-import.ts
|
|
199
542
|
const DYNAMIC_IMPORT_RE = /import\([^)]*\+\s*__webpack_require__[^+]*\)\.then/;
|
|
200
543
|
const DYNAMIC_IMPORT_REPLACE_RE = /import\([^)]*\+\s*(__webpack_require__[^+]*)\)\.then/g;
|
|
201
544
|
const HELPER_FILENAME = "_dynamic-import-helper.mjs";
|
|
202
|
-
const HELPER_IMPORT = `import { _rollupDynamicImport } from "./${HELPER_FILENAME}"
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
return transformed;
|
|
259
|
-
}
|
|
260
|
-
generateDynamicImportHelper(compilation) {
|
|
261
|
-
const chunkFiles = [];
|
|
262
|
-
for (const chunk of compilation.chunks) {
|
|
263
|
-
if (chunk.hasRuntime()) {
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
for (const filename of chunk.files) {
|
|
267
|
-
if (filename && isJS(filename)) {
|
|
268
|
-
chunkFiles.push(filename);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (chunkFiles.length === 0) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
const helperContent = this.generateHelperContent(chunkFiles);
|
|
276
|
-
compilation.emitAsset(HELPER_FILENAME, new compilation.compiler.webpack.sources.RawSource(helperContent));
|
|
277
|
-
}
|
|
278
|
-
generateHelperContent(chunkFiles) {
|
|
279
|
-
return `
|
|
545
|
+
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
|
+
var RollupCompatDynamicImportPlugin = class {
|
|
552
|
+
apply(compiler) {
|
|
553
|
+
compiler.hooks.compilation.tap("RollupCompatDynamicImportPlugin", (compilation) => {
|
|
554
|
+
compilation.hooks.processAssets.tapAsync({
|
|
555
|
+
name: "RollupCompatDynamicImportPlugin",
|
|
556
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE
|
|
557
|
+
}, (assets$1, callback) => {
|
|
558
|
+
try {
|
|
559
|
+
const targetFiles = /* @__PURE__ */ new Set();
|
|
560
|
+
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$1)) {
|
|
562
|
+
if (!isJS(filename)) continue;
|
|
563
|
+
if (!targetFiles.has(filename)) continue;
|
|
564
|
+
const source = asset.source();
|
|
565
|
+
const originalCode = typeof source === "string" ? source : source.toString();
|
|
566
|
+
if (!DYNAMIC_IMPORT_RE.test(originalCode)) continue;
|
|
567
|
+
const transformedCode = this.transformDynamicImports(originalCode);
|
|
568
|
+
if (transformedCode !== originalCode) assets$1[filename] = new compiler.webpack.sources.RawSource(transformedCode);
|
|
569
|
+
}
|
|
570
|
+
this.generateDynamicImportHelper(compilation);
|
|
571
|
+
callback();
|
|
572
|
+
} catch (error) {
|
|
573
|
+
callback(error);
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
transformDynamicImports(source) {
|
|
579
|
+
let transformed = source;
|
|
580
|
+
let needsHelperImport = false;
|
|
581
|
+
transformed = transformed.replace(DYNAMIC_IMPORT_REPLACE_RE, (match, filename) => {
|
|
582
|
+
needsHelperImport = true;
|
|
583
|
+
return `_rollupDynamicImport(${filename}).then`;
|
|
584
|
+
});
|
|
585
|
+
if (needsHelperImport && !transformed.includes(HELPER_IMPORT)) transformed = HELPER_IMPORT + transformed;
|
|
586
|
+
return transformed;
|
|
587
|
+
}
|
|
588
|
+
generateDynamicImportHelper(compilation) {
|
|
589
|
+
const chunkFiles = [];
|
|
590
|
+
for (const chunk of compilation.chunks) {
|
|
591
|
+
if (chunk.hasRuntime()) continue;
|
|
592
|
+
for (const filename of chunk.files) if (filename && isJS(filename)) chunkFiles.push(filename);
|
|
593
|
+
}
|
|
594
|
+
if (chunkFiles.length === 0) return;
|
|
595
|
+
const helperContent = this.generateHelperContent(chunkFiles);
|
|
596
|
+
compilation.emitAsset(HELPER_FILENAME, new compilation.compiler.webpack.sources.RawSource(helperContent));
|
|
597
|
+
}
|
|
598
|
+
generateHelperContent(chunkFiles) {
|
|
599
|
+
return `
|
|
280
600
|
// Rollup-compatible dynamic import helper generated by webpack
|
|
281
601
|
// This helper enables rollup to consume webpack chunks directly
|
|
282
602
|
|
|
@@ -293,1000 +613,920 @@ export function _rollupDynamicImport(chunkId) {
|
|
|
293
613
|
return chunk()
|
|
294
614
|
}
|
|
295
615
|
`;
|
|
296
|
-
|
|
297
|
-
}
|
|
616
|
+
}
|
|
617
|
+
};
|
|
298
618
|
|
|
619
|
+
//#endregion
|
|
620
|
+
//#region src/presets/base.ts
|
|
299
621
|
async function base(ctx) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
622
|
+
await applyPresets(ctx, [
|
|
623
|
+
baseAlias,
|
|
624
|
+
baseConfig,
|
|
625
|
+
basePlugins,
|
|
626
|
+
baseResolve,
|
|
627
|
+
baseTranspile
|
|
628
|
+
]);
|
|
307
629
|
}
|
|
308
630
|
function baseConfig(ctx) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
...ctx.config
|
|
327
|
-
});
|
|
631
|
+
ctx.config = defu({}, {
|
|
632
|
+
name: ctx.name,
|
|
633
|
+
entry: { app: [resolve(ctx.options.appDir, ctx.options.experimental.asyncEntry ? "entry.async" : "entry")] },
|
|
634
|
+
module: { rules: [] },
|
|
635
|
+
plugins: [],
|
|
636
|
+
externals: [],
|
|
637
|
+
optimization: {
|
|
638
|
+
...ctx.userConfig.optimization,
|
|
639
|
+
minimizer: []
|
|
640
|
+
},
|
|
641
|
+
experiments: { ...ctx.userConfig.experiments },
|
|
642
|
+
mode: ctx.isDev ? "development" : "production",
|
|
643
|
+
cache: getCache(ctx),
|
|
644
|
+
output: getOutput(ctx),
|
|
645
|
+
stats: statsMap[ctx.nuxt.options.logLevel] ?? statsMap.info,
|
|
646
|
+
...ctx.config
|
|
647
|
+
});
|
|
328
648
|
}
|
|
329
649
|
function basePlugins(ctx) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
},
|
|
370
|
-
done: (_, { stats }) => {
|
|
371
|
-
if (stats.hasErrors()) {
|
|
372
|
-
ctx.nuxt.callHook(`${builder}:error`);
|
|
373
|
-
} else {
|
|
374
|
-
logger.success(`Finished building ${stats.compilation.name ?? "Nuxt app"}`);
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
allDone: () => {
|
|
378
|
-
ctx.nuxt.callHook(`${builder}:done`);
|
|
379
|
-
},
|
|
380
|
-
progress: ({ webpackbar }) => {
|
|
381
|
-
ctx.nuxt.callHook(`${builder}:progress`, webpackbar.statesArray);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}));
|
|
386
|
-
}
|
|
387
|
-
if (ctx.isServer && !ctx.isDev) {
|
|
388
|
-
ctx.config.plugins.push(new RollupCompatDynamicImportPlugin());
|
|
389
|
-
}
|
|
650
|
+
ctx.config.plugins ||= [];
|
|
651
|
+
if (ctx.options.dev) {
|
|
652
|
+
if (ctx.nuxt.options.builder !== "@nuxt/rspack-builder") ctx.config.plugins.push(new TimeFixPlugin());
|
|
653
|
+
}
|
|
654
|
+
ctx.config.plugins.push(...ctx.userConfig.plugins || []);
|
|
655
|
+
if (ctx.nuxt.options.builder !== "@nuxt/rspack-builder") ctx.config.plugins.push(new WarningIgnorePlugin(getWarningIgnoreFilter(ctx)));
|
|
656
|
+
ctx.config.plugins.push(new webpack.DefinePlugin(getEnv(ctx)));
|
|
657
|
+
if (ctx.isServer || ctx.isDev && ctx.userConfig.friendlyErrors) ctx.config.plugins.push(new FriendlyErrorsWebpackPlugin({
|
|
658
|
+
clearConsole: false,
|
|
659
|
+
reporter: "consola",
|
|
660
|
+
logLevel: "ERROR"
|
|
661
|
+
}));
|
|
662
|
+
if (ctx.nuxt.options.webpack.profile) ctx.config.plugins.push(new WebpackBarPlugin({
|
|
663
|
+
name: ctx.name,
|
|
664
|
+
color: {
|
|
665
|
+
client: "green",
|
|
666
|
+
server: "orange",
|
|
667
|
+
modern: "blue"
|
|
668
|
+
}[ctx.name],
|
|
669
|
+
reporters: ["stats"],
|
|
670
|
+
stats: !ctx.isDev,
|
|
671
|
+
reporter: { reporter: {
|
|
672
|
+
change: (_, { shortPath }) => {
|
|
673
|
+
if (!ctx.isServer) ctx.nuxt.callHook(`${builder}:change`, shortPath);
|
|
674
|
+
},
|
|
675
|
+
done: (_, { stats }) => {
|
|
676
|
+
if (stats.hasErrors()) ctx.nuxt.callHook(`${builder}:error`);
|
|
677
|
+
else logger.success(`Finished building ${stats.compilation.name ?? "Nuxt app"}`);
|
|
678
|
+
},
|
|
679
|
+
allDone: () => {
|
|
680
|
+
ctx.nuxt.callHook(`${builder}:done`);
|
|
681
|
+
},
|
|
682
|
+
progress: ({ webpackbar }) => {
|
|
683
|
+
ctx.nuxt.callHook(`${builder}:progress`, webpackbar.statesArray);
|
|
684
|
+
}
|
|
685
|
+
} }
|
|
686
|
+
}));
|
|
687
|
+
if (ctx.isServer && !ctx.isDev) ctx.config.plugins.push(new RollupCompatDynamicImportPlugin());
|
|
390
688
|
}
|
|
391
689
|
function baseAlias(ctx) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
690
|
+
ctx.alias = {
|
|
691
|
+
"#app": ctx.options.appDir,
|
|
692
|
+
[basename(ctx.nuxt.options.dir.assets)]: resolve(ctx.nuxt.options.srcDir, ctx.nuxt.options.dir.assets),
|
|
693
|
+
...ctx.options.alias,
|
|
694
|
+
...ctx.alias
|
|
695
|
+
};
|
|
696
|
+
if (ctx.isClient) {
|
|
697
|
+
ctx.alias["nitro/runtime"] = resolve(ctx.nuxt.options.buildDir, "nitro.client.mjs");
|
|
698
|
+
ctx.alias["#internal/nitro"] = resolve(ctx.nuxt.options.buildDir, "nitro.client.mjs");
|
|
699
|
+
ctx.alias["nitropack/runtime"] = resolve(ctx.nuxt.options.buildDir, "nitro.client.mjs");
|
|
700
|
+
}
|
|
403
701
|
}
|
|
404
702
|
function baseResolve(ctx) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
703
|
+
const webpackModulesDir = ["node_modules"].concat(ctx.options.modulesDir);
|
|
704
|
+
ctx.config.resolve = {
|
|
705
|
+
extensions: [
|
|
706
|
+
".wasm",
|
|
707
|
+
".mjs",
|
|
708
|
+
".js",
|
|
709
|
+
".ts",
|
|
710
|
+
".json",
|
|
711
|
+
".vue",
|
|
712
|
+
".jsx",
|
|
713
|
+
".tsx"
|
|
714
|
+
],
|
|
715
|
+
alias: ctx.alias,
|
|
716
|
+
modules: webpackModulesDir,
|
|
717
|
+
fullySpecified: false,
|
|
718
|
+
...ctx.config.resolve
|
|
719
|
+
};
|
|
720
|
+
ctx.config.resolveLoader = {
|
|
721
|
+
modules: webpackModulesDir,
|
|
722
|
+
...ctx.config.resolveLoader
|
|
723
|
+
};
|
|
417
724
|
}
|
|
418
725
|
function baseTranspile(ctx) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
transpile.push(new RegExp(escapeRegExp(normalize(pattern))));
|
|
435
|
-
} else if (pattern instanceof RegExp) {
|
|
436
|
-
transpile.push(pattern);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
ctx.transpile = [...transpile, ...ctx.transpile];
|
|
726
|
+
const transpile = [
|
|
727
|
+
/\.vue\.js/i,
|
|
728
|
+
/consola\/src/,
|
|
729
|
+
/vue-demi/,
|
|
730
|
+
/(^|\/)nuxt\/(src\/|dist\/)?(app|[^/]+\/runtime)($|\/)/
|
|
731
|
+
];
|
|
732
|
+
for (let pattern of ctx.options.build.transpile) {
|
|
733
|
+
if (typeof pattern === "function") {
|
|
734
|
+
const result = pattern(ctx);
|
|
735
|
+
if (result) pattern = result;
|
|
736
|
+
}
|
|
737
|
+
if (typeof pattern === "string") transpile.push(new RegExp(escapeRegExp(normalize(pattern))));
|
|
738
|
+
else if (pattern instanceof RegExp) transpile.push(pattern);
|
|
739
|
+
}
|
|
740
|
+
ctx.transpile = [...transpile, ...ctx.transpile];
|
|
440
741
|
}
|
|
441
742
|
function getCache(ctx) {
|
|
442
|
-
|
|
443
|
-
return false;
|
|
444
|
-
}
|
|
743
|
+
if (!ctx.options.dev) return false;
|
|
445
744
|
}
|
|
446
745
|
function getOutput(ctx) {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
746
|
+
return {
|
|
747
|
+
path: resolve(ctx.options.buildDir, "dist", ctx.isServer ? "server" : joinURL("client", ctx.options.app.buildAssetsDir)),
|
|
748
|
+
filename: fileName(ctx, "app"),
|
|
749
|
+
chunkFilename: fileName(ctx, "chunk"),
|
|
750
|
+
publicPath: joinURL(ctx.options.app.baseURL, ctx.options.app.buildAssetsDir)
|
|
751
|
+
};
|
|
453
752
|
}
|
|
454
753
|
function getWarningIgnoreFilter(ctx) {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
(warn) => warn.name === "ModuleDependencyWarning" && warn.message.includes("export 'default'") && warn.message.includes("nuxt_plugin_"),
|
|
458
|
-
...ctx.userConfig.warningIgnoreFilters || []
|
|
459
|
-
];
|
|
460
|
-
return (warn) => !filters.some((ignoreFilter) => ignoreFilter(warn));
|
|
754
|
+
const filters = [(warn) => warn.name === "ModuleDependencyWarning" && warn.message.includes("export 'default'") && warn.message.includes("nuxt_plugin_"), ...ctx.userConfig.warningIgnoreFilters || []];
|
|
755
|
+
return (warn) => !filters.some((ignoreFilter) => ignoreFilter(warn));
|
|
461
756
|
}
|
|
462
757
|
function getEnv(ctx) {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
758
|
+
const _env = {
|
|
759
|
+
"process.env.NODE_ENV": JSON.stringify(ctx.config.mode),
|
|
760
|
+
"__NUXT_VERSION__": JSON.stringify(ctx.nuxt._version),
|
|
761
|
+
"__NUXT_ASYNC_CONTEXT__": ctx.options.experimental.asyncContext,
|
|
762
|
+
"process.env.VUE_ENV": JSON.stringify(ctx.name),
|
|
763
|
+
"process.dev": ctx.options.dev,
|
|
764
|
+
"process.test": isTest,
|
|
765
|
+
"process.browser": ctx.isClient,
|
|
766
|
+
"process.client": ctx.isClient,
|
|
767
|
+
"process.server": ctx.isServer,
|
|
768
|
+
"import.meta.dev": ctx.options.dev,
|
|
769
|
+
"import.meta.test": isTest,
|
|
770
|
+
"import.meta.browser": ctx.isClient,
|
|
771
|
+
"import.meta.client": ctx.isClient,
|
|
772
|
+
"import.meta.server": ctx.isServer
|
|
773
|
+
};
|
|
774
|
+
if (ctx.isClient) {
|
|
775
|
+
_env["process.prerender"] = false;
|
|
776
|
+
_env["process.nitro"] = false;
|
|
777
|
+
_env["import.meta.prerender"] = false;
|
|
778
|
+
_env["import.meta.nitro"] = false;
|
|
779
|
+
} else {
|
|
780
|
+
_env["process.prerender"] = "(()=>process.prerender)()";
|
|
781
|
+
_env["process.nitro"] = "(()=>process.nitro)()";
|
|
782
|
+
_env["import.meta.prerender"] = "(()=>import.meta.prerender)()";
|
|
783
|
+
_env["import.meta.nitro"] = "(()=>import.meta.nitro)()";
|
|
784
|
+
}
|
|
785
|
+
if (ctx.userConfig.aggressiveCodeRemoval) {
|
|
786
|
+
_env["typeof process"] = JSON.stringify(ctx.isServer ? "object" : "undefined");
|
|
787
|
+
_env["typeof window"] = _env["typeof document"] = JSON.stringify(!ctx.isServer ? "object" : "undefined");
|
|
788
|
+
}
|
|
789
|
+
return _env;
|
|
495
790
|
}
|
|
496
791
|
const statsMap = {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
792
|
+
silent: "none",
|
|
793
|
+
info: "normal",
|
|
794
|
+
verbose: "verbose"
|
|
500
795
|
};
|
|
501
796
|
|
|
797
|
+
//#endregion
|
|
798
|
+
//#region src/presets/esbuild.ts
|
|
502
799
|
function esbuild(ctx) {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
options: {
|
|
529
|
-
target,
|
|
530
|
-
...ctx.nuxt.options.webpack.loaders.esbuild,
|
|
531
|
-
loader: "tsx"
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
);
|
|
800
|
+
const target = ctx.isServer ? "es2020" : "chrome85";
|
|
801
|
+
ctx.config.optimization.minimizer.push(new EsbuildPlugin());
|
|
802
|
+
ctx.config.module.rules.push({
|
|
803
|
+
test: /\.m?[jt]s$/i,
|
|
804
|
+
loader: "esbuild-loader",
|
|
805
|
+
exclude: (file) => {
|
|
806
|
+
const lastSegment = file.split("node_modules", 2)[1];
|
|
807
|
+
if (!lastSegment) return false;
|
|
808
|
+
return !ctx.transpile.some((module) => module.test(lastSegment));
|
|
809
|
+
},
|
|
810
|
+
resolve: { fullySpecified: false },
|
|
811
|
+
options: {
|
|
812
|
+
target,
|
|
813
|
+
...ctx.nuxt.options.webpack.loaders.esbuild,
|
|
814
|
+
loader: "ts"
|
|
815
|
+
}
|
|
816
|
+
}, {
|
|
817
|
+
test: /\.m?[jt]sx$/,
|
|
818
|
+
loader: "esbuild-loader",
|
|
819
|
+
options: {
|
|
820
|
+
target,
|
|
821
|
+
...ctx.nuxt.options.webpack.loaders.esbuild,
|
|
822
|
+
loader: "tsx"
|
|
823
|
+
}
|
|
824
|
+
});
|
|
535
825
|
}
|
|
536
826
|
|
|
827
|
+
//#endregion
|
|
828
|
+
//#region src/presets/pug.ts
|
|
537
829
|
function pug(ctx) {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
{
|
|
552
|
-
loader: "pug-plain-loader",
|
|
553
|
-
options: ctx.userConfig.loaders.pugPlain
|
|
554
|
-
}
|
|
555
|
-
]
|
|
556
|
-
}
|
|
557
|
-
]
|
|
558
|
-
});
|
|
830
|
+
ctx.config.module.rules.push({
|
|
831
|
+
test: /\.pug$/i,
|
|
832
|
+
oneOf: [{
|
|
833
|
+
resourceQuery: /^\?vue/i,
|
|
834
|
+
use: [{
|
|
835
|
+
loader: "pug-plain-loader",
|
|
836
|
+
options: ctx.userConfig.loaders.pugPlain
|
|
837
|
+
}]
|
|
838
|
+
}, { use: ["raw-loader", {
|
|
839
|
+
loader: "pug-plain-loader",
|
|
840
|
+
options: ctx.userConfig.loaders.pugPlain
|
|
841
|
+
}] }]
|
|
842
|
+
});
|
|
559
843
|
}
|
|
560
844
|
|
|
845
|
+
//#endregion
|
|
846
|
+
//#region src/utils/postcss.ts
|
|
561
847
|
const isPureObject = (obj) => obj !== null && !Array.isArray(obj) && typeof obj === "object";
|
|
562
848
|
function sortPlugins({ plugins, order }) {
|
|
563
|
-
|
|
564
|
-
|
|
849
|
+
const names = Object.keys(plugins);
|
|
850
|
+
return typeof order === "function" ? order(names) : order || names;
|
|
565
851
|
}
|
|
566
|
-
async function getPostcssConfig(nuxt) {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
console.warn(`[nuxt] could not import postcss plugin \`${pluginName}\`. Please report this as a bug.`);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
postcssOptions.plugins = plugins;
|
|
609
|
-
}
|
|
610
|
-
return {
|
|
611
|
-
sourceMap: nuxt.options.webpack.cssSourceMap,
|
|
612
|
-
...nuxt.options.webpack.postcss,
|
|
613
|
-
postcssOptions
|
|
614
|
-
};
|
|
852
|
+
async function getPostcssConfig(nuxt$1) {
|
|
853
|
+
if (!nuxt$1.options.webpack.postcss || !nuxt$1.options.postcss) return false;
|
|
854
|
+
const postcssOptions = defu({}, nuxt$1.options.postcss, {
|
|
855
|
+
plugins: {
|
|
856
|
+
"postcss-import": { resolve: createResolver({
|
|
857
|
+
alias: { ...nuxt$1.options.alias },
|
|
858
|
+
modules: nuxt$1.options.modulesDir
|
|
859
|
+
}) },
|
|
860
|
+
"postcss-url": {}
|
|
861
|
+
},
|
|
862
|
+
sourceMap: nuxt$1.options.webpack.cssSourceMap
|
|
863
|
+
});
|
|
864
|
+
const jiti = createJiti(nuxt$1.options.rootDir, { alias: nuxt$1.options.alias });
|
|
865
|
+
if (!Array.isArray(postcssOptions.plugins) && isPureObject(postcssOptions.plugins)) {
|
|
866
|
+
const plugins = [];
|
|
867
|
+
for (const pluginName$1 of sortPlugins(postcssOptions)) {
|
|
868
|
+
const pluginOptions = postcssOptions.plugins[pluginName$1];
|
|
869
|
+
if (!pluginOptions) continue;
|
|
870
|
+
let pluginFn;
|
|
871
|
+
for (const parentURL of nuxt$1.options.modulesDir) {
|
|
872
|
+
pluginFn = await jiti.import(pluginName$1, {
|
|
873
|
+
parentURL: parentURL.replace(/\/node_modules\/?$/, ""),
|
|
874
|
+
try: true,
|
|
875
|
+
default: true
|
|
876
|
+
});
|
|
877
|
+
if (typeof pluginFn === "function") {
|
|
878
|
+
plugins.push(pluginFn(pluginOptions));
|
|
879
|
+
break;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
if (typeof pluginFn !== "function") console.warn(`[nuxt] could not import postcss plugin \`${pluginName$1}\`. Please report this as a bug.`);
|
|
883
|
+
}
|
|
884
|
+
postcssOptions.plugins = plugins;
|
|
885
|
+
}
|
|
886
|
+
return {
|
|
887
|
+
sourceMap: nuxt$1.options.webpack.cssSourceMap,
|
|
888
|
+
...nuxt$1.options.webpack.postcss,
|
|
889
|
+
postcssOptions
|
|
890
|
+
};
|
|
615
891
|
}
|
|
616
892
|
|
|
893
|
+
//#endregion
|
|
894
|
+
//#region src/presets/style.ts
|
|
617
895
|
async function style(ctx) {
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
896
|
+
await applyPresets(ctx, [
|
|
897
|
+
loaders,
|
|
898
|
+
extractCSS,
|
|
899
|
+
minimizer
|
|
900
|
+
]);
|
|
623
901
|
}
|
|
624
902
|
function minimizer(ctx) {
|
|
625
|
-
|
|
626
|
-
ctx.config.optimization.minimizer.push(new CssMinimizerPlugin({
|
|
627
|
-
...ctx.userConfig.optimizeCSS
|
|
628
|
-
}));
|
|
629
|
-
}
|
|
903
|
+
if (ctx.userConfig.optimizeCSS && Array.isArray(ctx.config.optimization.minimizer)) ctx.config.optimization.minimizer.push(new CssMinimizerPlugin({ ...ctx.userConfig.optimizeCSS }));
|
|
630
904
|
}
|
|
631
905
|
function extractCSS(ctx) {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
...config === true ? {} : config
|
|
641
|
-
}));
|
|
906
|
+
const config = ctx.userConfig.extractCSS;
|
|
907
|
+
if (!config) return;
|
|
908
|
+
const filename = fileName(ctx, "css");
|
|
909
|
+
ctx.config.plugins.push(new MiniCssExtractPlugin({
|
|
910
|
+
filename,
|
|
911
|
+
chunkFilename: filename,
|
|
912
|
+
...config === true ? {} : config
|
|
913
|
+
}));
|
|
642
914
|
}
|
|
643
915
|
async function loaders(ctx) {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
916
|
+
ctx.config.module.rules.push(await createdStyleRule("css", /\.css$/i, null, ctx));
|
|
917
|
+
ctx.config.module.rules.push(await createdStyleRule("postcss", /\.p(ost)?css$/i, null, ctx));
|
|
918
|
+
const lessLoader = {
|
|
919
|
+
loader: "less-loader",
|
|
920
|
+
options: ctx.userConfig.loaders.less
|
|
921
|
+
};
|
|
922
|
+
ctx.config.module.rules.push(await createdStyleRule("less", /\.less$/i, lessLoader, ctx));
|
|
923
|
+
const sassLoader = {
|
|
924
|
+
loader: "sass-loader",
|
|
925
|
+
options: ctx.userConfig.loaders.sass
|
|
926
|
+
};
|
|
927
|
+
ctx.config.module.rules.push(await createdStyleRule("sass", /\.sass$/i, sassLoader, ctx));
|
|
928
|
+
const scssLoader = {
|
|
929
|
+
loader: "sass-loader",
|
|
930
|
+
options: ctx.userConfig.loaders.scss
|
|
931
|
+
};
|
|
932
|
+
ctx.config.module.rules.push(await createdStyleRule("scss", /\.scss$/i, scssLoader, ctx));
|
|
933
|
+
const stylusLoader = {
|
|
934
|
+
loader: "stylus-loader",
|
|
935
|
+
options: ctx.userConfig.loaders.stylus
|
|
936
|
+
};
|
|
937
|
+
ctx.config.module.rules.push(await createdStyleRule("stylus", /\.styl(us)?$/i, stylusLoader, ctx));
|
|
654
938
|
}
|
|
655
939
|
async function createdStyleRule(lang, test, processorLoader, ctx) {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
// This matches <style module>
|
|
667
|
-
{
|
|
668
|
-
resourceQuery: /module/,
|
|
669
|
-
use: cssModuleLoaders.concat(styleLoaders)
|
|
670
|
-
},
|
|
671
|
-
// This matches plain <style> or <style scoped>
|
|
672
|
-
{
|
|
673
|
-
use: cssLoaders.concat(styleLoaders)
|
|
674
|
-
}
|
|
675
|
-
]
|
|
676
|
-
};
|
|
940
|
+
const styleLoaders = [await createPostcssLoadersRule(ctx), processorLoader].filter(Boolean);
|
|
941
|
+
ctx.userConfig.loaders.css.importLoaders = ctx.userConfig.loaders.cssModules.importLoaders = styleLoaders.length;
|
|
942
|
+
const cssLoaders = createCssLoadersRule(ctx, ctx.userConfig.loaders.css);
|
|
943
|
+
return {
|
|
944
|
+
test,
|
|
945
|
+
oneOf: [{
|
|
946
|
+
resourceQuery: /module/,
|
|
947
|
+
use: createCssLoadersRule(ctx, ctx.userConfig.loaders.cssModules).concat(styleLoaders)
|
|
948
|
+
}, { use: cssLoaders.concat(styleLoaders) }]
|
|
949
|
+
};
|
|
677
950
|
}
|
|
678
951
|
function createCssLoadersRule(ctx, cssLoaderOptions) {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
cssLoader
|
|
692
|
-
];
|
|
693
|
-
}
|
|
694
|
-
return [
|
|
695
|
-
// https://github.com/vuejs/vue-style-loader/issues/56
|
|
696
|
-
// {
|
|
697
|
-
// loader: 'vue-style-loader',
|
|
698
|
-
// options: options.webpack.loaders.vueStyle
|
|
699
|
-
// },
|
|
700
|
-
cssLoader
|
|
701
|
-
];
|
|
952
|
+
const cssLoader = {
|
|
953
|
+
loader: "css-loader",
|
|
954
|
+
options: cssLoaderOptions
|
|
955
|
+
};
|
|
956
|
+
if (ctx.userConfig.extractCSS) {
|
|
957
|
+
if (ctx.isServer) {
|
|
958
|
+
if (cssLoader.options.modules) cssLoader.options.modules.exportOnlyLocals ??= true;
|
|
959
|
+
return [cssLoader];
|
|
960
|
+
}
|
|
961
|
+
return [{ loader: MiniCssExtractPlugin.loader }, cssLoader];
|
|
962
|
+
}
|
|
963
|
+
return [cssLoader];
|
|
702
964
|
}
|
|
703
965
|
async function createPostcssLoadersRule(ctx) {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
return {
|
|
712
|
-
loader: "postcss-loader",
|
|
713
|
-
options: config
|
|
714
|
-
};
|
|
966
|
+
if (!ctx.options.postcss) return;
|
|
967
|
+
const config = await getPostcssConfig(ctx.nuxt);
|
|
968
|
+
if (!config) return;
|
|
969
|
+
return {
|
|
970
|
+
loader: "postcss-loader",
|
|
971
|
+
options: config
|
|
972
|
+
};
|
|
715
973
|
}
|
|
716
974
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
for (const m2 of stats.modules) {
|
|
806
|
-
if (m2.assets?.length && m2.chunks?.includes(cid)) {
|
|
807
|
-
files.push(...m2.assets.map(fileToIndex));
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
const manifest = normalizeWebpackManifest(webpackManifest);
|
|
813
|
-
await this.nuxt.callHook("build:manifest", manifest);
|
|
814
|
-
await mkdir(this.serverDist, { recursive: true });
|
|
815
|
-
const precomputed = precomputeDependencies(manifest);
|
|
816
|
-
await writeFile(join(this.serverDist, `client.manifest.json`), JSON.stringify(manifest, null, 2));
|
|
817
|
-
await writeFile(join(this.serverDist, "client.manifest.mjs"), "export default " + serialize(manifest), "utf8");
|
|
818
|
-
await writeFile(join(this.serverDist, "client.precomputed.mjs"), "export default " + serialize(precomputed), "utf8");
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
}
|
|
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
|
+
var VueSSRClientPlugin = class {
|
|
982
|
+
serverDist;
|
|
983
|
+
nuxt;
|
|
984
|
+
constructor(options) {
|
|
985
|
+
this.serverDist = resolve(options.nuxt.options.buildDir, "dist/server");
|
|
986
|
+
this.nuxt = options.nuxt;
|
|
987
|
+
}
|
|
988
|
+
getRelativeModuleId(identifier, context) {
|
|
989
|
+
const id = identifier.replace(/\s\w+$/, "");
|
|
990
|
+
const resourceMatch = id.match(/([^!]*\.vue)(?:\?|$)/);
|
|
991
|
+
return resourceMatch && resourceMatch[1] ? normalize(relative(context, resourceMatch[1])).replace(/^\.\//, "").replace(/\\/g, "/") : id;
|
|
992
|
+
}
|
|
993
|
+
apply(compiler) {
|
|
994
|
+
compiler.hooks.afterEmit.tap("VueSSRClientPlugin", async (compilation) => {
|
|
995
|
+
const stats = compilation.getStats().toJson();
|
|
996
|
+
const context = this.nuxt.options.srcDir;
|
|
997
|
+
const initialFiles = /* @__PURE__ */ new Set();
|
|
998
|
+
for (const { assets: assets$1 } of Object.values(stats.entrypoints)) {
|
|
999
|
+
if (!assets$1) continue;
|
|
1000
|
+
for (const asset of assets$1) {
|
|
1001
|
+
const file = asset.name;
|
|
1002
|
+
if ((isJS(file) || isCSS(file)) && !isHotUpdate(file)) initialFiles.add(file);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
const allFiles = /* @__PURE__ */ new Set();
|
|
1006
|
+
const asyncFiles = /* @__PURE__ */ new Set();
|
|
1007
|
+
const assetsMapping = {};
|
|
1008
|
+
for (const { name: file, chunkNames = [] } of stats.assets) {
|
|
1009
|
+
if (isHotUpdate(file)) continue;
|
|
1010
|
+
allFiles.add(file);
|
|
1011
|
+
const isFileJS = isJS(file);
|
|
1012
|
+
if (!initialFiles.has(file) && (isFileJS || isCSS(file))) asyncFiles.add(file);
|
|
1013
|
+
if (isFileJS) {
|
|
1014
|
+
const componentHash = hash(chunkNames.join("|"));
|
|
1015
|
+
(assetsMapping[componentHash] ||= []).push(file);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
const webpackManifest = {
|
|
1019
|
+
publicPath: stats.publicPath,
|
|
1020
|
+
all: [...allFiles],
|
|
1021
|
+
initial: [...initialFiles],
|
|
1022
|
+
async: [...asyncFiles],
|
|
1023
|
+
modules: {},
|
|
1024
|
+
assetsMapping
|
|
1025
|
+
};
|
|
1026
|
+
const { entrypoints = {}, namedChunkGroups = {} } = stats;
|
|
1027
|
+
const fileToIndex = (file) => webpackManifest.all.indexOf(String(file));
|
|
1028
|
+
for (const m of stats.modules) {
|
|
1029
|
+
if (m.chunks?.length !== 1) continue;
|
|
1030
|
+
const [cid] = m.chunks;
|
|
1031
|
+
const chunk = stats.chunks.find((c) => c.id === cid);
|
|
1032
|
+
if (!chunk || !chunk.files || !cid) continue;
|
|
1033
|
+
const relativeId = this.getRelativeModuleId(m.identifier, context);
|
|
1034
|
+
const filesSet = /* @__PURE__ */ new Set();
|
|
1035
|
+
for (const file of chunk.files) {
|
|
1036
|
+
const index = fileToIndex(file);
|
|
1037
|
+
if (index !== -1) filesSet.add(index);
|
|
1038
|
+
}
|
|
1039
|
+
for (const chunkName of chunk.names) if (!entrypoints[chunkName]) {
|
|
1040
|
+
const chunkGroup = namedChunkGroups[chunkName];
|
|
1041
|
+
if (chunkGroup) for (const asset of chunkGroup.assets) filesSet.add(fileToIndex(asset.name));
|
|
1042
|
+
}
|
|
1043
|
+
const files = Array.from(filesSet);
|
|
1044
|
+
webpackManifest.modules[relativeId] = files;
|
|
1045
|
+
if (Array.isArray(m.modules)) for (const concatenatedModule of m.modules) {
|
|
1046
|
+
const relativeId$1 = this.getRelativeModuleId(concatenatedModule.identifier, context);
|
|
1047
|
+
webpackManifest.modules[relativeId$1] ||= files;
|
|
1048
|
+
}
|
|
1049
|
+
if (stats.modules) {
|
|
1050
|
+
for (const m$1 of stats.modules) if (m$1.assets?.length && m$1.chunks?.includes(cid)) files.push(...m$1.assets.map(fileToIndex));
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
const manifest = normalizeWebpackManifest(webpackManifest);
|
|
1054
|
+
await this.nuxt.callHook("build:manifest", manifest);
|
|
1055
|
+
await mkdir(this.serverDist, { recursive: true });
|
|
1056
|
+
const precomputed = precomputeDependencies(manifest);
|
|
1057
|
+
await writeFile(join(this.serverDist, `client.manifest.json`), JSON.stringify(manifest, null, 2));
|
|
1058
|
+
await writeFile(join(this.serverDist, "client.manifest.mjs"), "export default " + serialize(manifest), "utf8");
|
|
1059
|
+
await writeFile(join(this.serverDist, "client.precomputed.mjs"), "export default " + serialize(precomputed), "utf8");
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
822
1063
|
|
|
1064
|
+
//#endregion
|
|
1065
|
+
//#region src/plugins/vue/server.ts
|
|
823
1066
|
const JS_MAP_RE = /\.js\.map$/;
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
} else {
|
|
872
|
-
delete assets[asset.name];
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
const src = JSON.stringify(bundle, null, 2);
|
|
876
|
-
assets[this.options.filename] = {
|
|
877
|
-
source: () => src,
|
|
878
|
-
size: () => src.length
|
|
879
|
-
};
|
|
880
|
-
const mjsSrc = "export default " + src;
|
|
881
|
-
assets[this.options.filename.replace(".json", ".mjs")] = {
|
|
882
|
-
source: () => mjsSrc,
|
|
883
|
-
map: () => null,
|
|
884
|
-
size: () => mjsSrc.length
|
|
885
|
-
};
|
|
886
|
-
cb();
|
|
887
|
-
});
|
|
888
|
-
});
|
|
889
|
-
}
|
|
890
|
-
}
|
|
1067
|
+
var VueSSRServerPlugin = class {
|
|
1068
|
+
options;
|
|
1069
|
+
constructor(options = {}) {
|
|
1070
|
+
this.options = Object.assign({ filename: null }, options);
|
|
1071
|
+
}
|
|
1072
|
+
apply(compiler) {
|
|
1073
|
+
validate(compiler);
|
|
1074
|
+
compiler.hooks.make.tap("VueSSRServerPlugin", (compilation) => {
|
|
1075
|
+
compilation.hooks.processAssets.tapAsync({
|
|
1076
|
+
name: "VueSSRServerPlugin",
|
|
1077
|
+
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
1078
|
+
}, (assets$1, cb) => {
|
|
1079
|
+
const stats = compilation.getStats().toJson();
|
|
1080
|
+
const [entryName] = Object.keys(stats.entrypoints);
|
|
1081
|
+
const entryInfo = stats.entrypoints[entryName];
|
|
1082
|
+
if (!entryInfo) return cb();
|
|
1083
|
+
const entryAssets = entryInfo.assets.filter((asset) => isJS(asset.name));
|
|
1084
|
+
if (entryAssets.length > 1) throw new Error("Server-side bundle should have one single entry file. Avoid using CommonsChunkPlugin in the server config.");
|
|
1085
|
+
const [entry] = entryAssets;
|
|
1086
|
+
if (!entry || typeof entry.name !== "string") throw new Error(`Entry "${entryName}" not found. Did you specify the correct entry option?`);
|
|
1087
|
+
const bundle$1 = {
|
|
1088
|
+
entry: entry.name,
|
|
1089
|
+
files: {},
|
|
1090
|
+
maps: {}
|
|
1091
|
+
};
|
|
1092
|
+
for (const asset of stats.assets) if (isJS(asset.name)) {
|
|
1093
|
+
const queryPart = extractQueryPartJS(asset.name);
|
|
1094
|
+
if (queryPart !== void 0) bundle$1.files[asset.name] = asset.name.replace(queryPart, "");
|
|
1095
|
+
else bundle$1.files[asset.name] = asset.name;
|
|
1096
|
+
} else if (JS_MAP_RE.test(asset.name)) bundle$1.maps[asset.name.replace(/\.map$/, "")] = asset.name;
|
|
1097
|
+
else delete assets$1[asset.name];
|
|
1098
|
+
const src = JSON.stringify(bundle$1, null, 2);
|
|
1099
|
+
assets$1[this.options.filename] = {
|
|
1100
|
+
source: () => src,
|
|
1101
|
+
size: () => src.length
|
|
1102
|
+
};
|
|
1103
|
+
const mjsSrc = "export default " + src;
|
|
1104
|
+
assets$1[this.options.filename.replace(".json", ".mjs")] = {
|
|
1105
|
+
source: () => mjsSrc,
|
|
1106
|
+
map: () => null,
|
|
1107
|
+
size: () => mjsSrc.length
|
|
1108
|
+
};
|
|
1109
|
+
cb();
|
|
1110
|
+
});
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
891
1114
|
|
|
1115
|
+
//#endregion
|
|
1116
|
+
//#region src/presets/vue.ts
|
|
892
1117
|
function vue(ctx) {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
1118
|
+
ctx.config.plugins.push(new (VueLoaderPlugin.default || VueLoaderPlugin)());
|
|
1119
|
+
ctx.config.module.rules.push({
|
|
1120
|
+
test: /\.vue$/i,
|
|
1121
|
+
loader: "vue-loader",
|
|
1122
|
+
options: {
|
|
1123
|
+
...ctx.userConfig.loaders.vue,
|
|
1124
|
+
isServerBuild: ctx.isServer
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
if (ctx.isClient) ctx.config.plugins.push(new VueSSRClientPlugin({ nuxt: ctx.nuxt }));
|
|
1128
|
+
else {
|
|
1129
|
+
ctx.config.plugins.push(new VueSSRServerPlugin({ filename: `${ctx.name}.manifest.json` }));
|
|
1130
|
+
const loaderPath = resolveModulePath("#vue-module-identifier", { from: import.meta.url });
|
|
1131
|
+
ctx.config.module.rules.push({
|
|
1132
|
+
test: /\.vue$/i,
|
|
1133
|
+
enforce: "post",
|
|
1134
|
+
use: [{
|
|
1135
|
+
loader: loaderPath,
|
|
1136
|
+
options: { srcDir: ctx.nuxt.options.srcDir }
|
|
1137
|
+
}]
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
ctx.config.plugins.push(new webpack.DefinePlugin({
|
|
1141
|
+
"__VUE_OPTIONS_API__": "true",
|
|
1142
|
+
"__VUE_PROD_DEVTOOLS__": "false",
|
|
1143
|
+
"__VUE_PROD_HYDRATION_MISMATCH_DETAILS__": ctx.nuxt.options.debug && ctx.nuxt.options.debug.hydration
|
|
1144
|
+
}));
|
|
911
1145
|
}
|
|
912
1146
|
|
|
1147
|
+
//#endregion
|
|
1148
|
+
//#region src/presets/nuxt.ts
|
|
913
1149
|
async function nuxt(ctx) {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1150
|
+
await applyPresets(ctx, [
|
|
1151
|
+
base,
|
|
1152
|
+
assets,
|
|
1153
|
+
esbuild,
|
|
1154
|
+
pug,
|
|
1155
|
+
style,
|
|
1156
|
+
vue
|
|
1157
|
+
]);
|
|
922
1158
|
}
|
|
923
1159
|
|
|
1160
|
+
//#endregion
|
|
1161
|
+
//#region src/configs/client.ts
|
|
924
1162
|
async function client(ctx) {
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1163
|
+
ctx.name = "client";
|
|
1164
|
+
ctx.isClient = true;
|
|
1165
|
+
await applyPresets(ctx, [
|
|
1166
|
+
nuxt,
|
|
1167
|
+
clientPlugins,
|
|
1168
|
+
clientOptimization,
|
|
1169
|
+
clientDevtool,
|
|
1170
|
+
clientPerformance,
|
|
1171
|
+
clientHMR,
|
|
1172
|
+
clientNodeCompat
|
|
1173
|
+
]);
|
|
936
1174
|
}
|
|
937
1175
|
function clientDevtool(ctx) {
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
1176
|
+
if (!ctx.nuxt.options.sourcemap.client) {
|
|
1177
|
+
ctx.config.devtool = false;
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
const prefix = ctx.nuxt.options.sourcemap.client === "hidden" ? "hidden-" : "";
|
|
1181
|
+
if (!ctx.isDev) {
|
|
1182
|
+
ctx.config.devtool = prefix + "source-map";
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
ctx.config.devtool = prefix + "eval-cheap-module-source-map";
|
|
948
1186
|
}
|
|
949
1187
|
function clientPerformance(ctx) {
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1188
|
+
ctx.config.performance = {
|
|
1189
|
+
maxEntrypointSize: 1e3 * 1024,
|
|
1190
|
+
hints: ctx.isDev ? false : "warning",
|
|
1191
|
+
...ctx.config.performance
|
|
1192
|
+
};
|
|
955
1193
|
}
|
|
956
1194
|
function clientNodeCompat(ctx) {
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
resource.request = resource.request.replace(/^node:/, "");
|
|
971
|
-
}));
|
|
1195
|
+
if (!ctx.nuxt.options.experimental.clientNodeCompat) return;
|
|
1196
|
+
ctx.config.plugins.push(new webpack.DefinePlugin({ global: "globalThis" }));
|
|
1197
|
+
ctx.config.resolve ||= {};
|
|
1198
|
+
ctx.config.resolve.fallback = {
|
|
1199
|
+
...defineEnv({
|
|
1200
|
+
nodeCompat: true,
|
|
1201
|
+
resolve: true
|
|
1202
|
+
}).env.alias,
|
|
1203
|
+
...ctx.config.resolve.fallback
|
|
1204
|
+
};
|
|
1205
|
+
ctx.config.plugins.unshift(new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
|
|
1206
|
+
resource.request = resource.request.replace(/^node:/, "");
|
|
1207
|
+
}));
|
|
972
1208
|
}
|
|
973
1209
|
function clientHMR(ctx) {
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
app.unshift(
|
|
990
|
-
// https://github.com/webpack/webpack-hot-middleware#config
|
|
991
|
-
`webpack-hot-middleware/client?${hotMiddlewareClientOptionsStr}`
|
|
992
|
-
);
|
|
993
|
-
ctx.config.plugins ||= [];
|
|
994
|
-
ctx.config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
1210
|
+
if (!ctx.isDev) return;
|
|
1211
|
+
const clientOptions = ctx.userConfig.hotMiddleware?.client || {};
|
|
1212
|
+
const hotMiddlewareClientOptions = {
|
|
1213
|
+
reload: true,
|
|
1214
|
+
timeout: 3e4,
|
|
1215
|
+
path: joinURL(ctx.options.app.baseURL, "__webpack_hmr", ctx.name),
|
|
1216
|
+
...clientOptions,
|
|
1217
|
+
ansiColors: JSON.stringify(clientOptions.ansiColors || {}),
|
|
1218
|
+
overlayStyles: JSON.stringify(clientOptions.overlayStyles || {}),
|
|
1219
|
+
name: ctx.name
|
|
1220
|
+
};
|
|
1221
|
+
const hotMiddlewareClientOptionsStr = querystring.stringify(hotMiddlewareClientOptions);
|
|
1222
|
+
ctx.config.entry.app.unshift(`webpack-hot-middleware/client?${hotMiddlewareClientOptionsStr}`);
|
|
1223
|
+
ctx.config.plugins ||= [];
|
|
1224
|
+
ctx.config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
995
1225
|
}
|
|
996
|
-
function clientOptimization(
|
|
1226
|
+
function clientOptimization(ctx) {
|
|
1227
|
+
if (!ctx.nuxt.options.features.inlineStyles) return;
|
|
1228
|
+
const globalCSSPaths = /* @__PURE__ */ new Set();
|
|
1229
|
+
for (const css of ctx.options.css) if (typeof css === "string") {
|
|
1230
|
+
const resolved = resolveAlias(css, ctx.options.alias);
|
|
1231
|
+
globalCSSPaths.add(normalize(resolved));
|
|
1232
|
+
}
|
|
1233
|
+
if (globalCSSPaths.size > 0) {
|
|
1234
|
+
ctx.config.optimization ||= {};
|
|
1235
|
+
ctx.config.optimization.splitChunks ||= {};
|
|
1236
|
+
ctx.config.optimization.splitChunks.cacheGroups ||= {};
|
|
1237
|
+
ctx.config.optimization.splitChunks.cacheGroups.nuxtGlobalCSS = {
|
|
1238
|
+
name: "nuxt-global-css",
|
|
1239
|
+
chunks: "all",
|
|
1240
|
+
enforce: true,
|
|
1241
|
+
test: (module) => {
|
|
1242
|
+
if (module.type !== "css/mini-extract") return false;
|
|
1243
|
+
const identifier = normalize(module.identifier());
|
|
1244
|
+
for (const globalPath of globalCSSPaths) if (identifier.includes(globalPath)) return true;
|
|
1245
|
+
return false;
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
997
1249
|
}
|
|
998
1250
|
function clientPlugins(ctx) {
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
logger
|
|
1015
|
-
}));
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1251
|
+
if (!ctx.isDev && !ctx.nuxt.options.test && ctx.name === "client" && ctx.userConfig.analyze && (ctx.userConfig.analyze === true || ctx.userConfig.analyze.enabled)) {
|
|
1252
|
+
const statsDir = resolve(ctx.options.analyzeDir);
|
|
1253
|
+
ctx.config.plugins.push(new BundleAnalyzerPlugin({
|
|
1254
|
+
analyzerMode: "static",
|
|
1255
|
+
defaultSizes: "gzip",
|
|
1256
|
+
generateStatsFile: true,
|
|
1257
|
+
openAnalyzer: true,
|
|
1258
|
+
reportFilename: resolve(statsDir, `${ctx.name}.html`),
|
|
1259
|
+
statsFilename: resolve(statsDir, `${ctx.name}.json`),
|
|
1260
|
+
...ctx.userConfig.analyze === true ? {} : ctx.userConfig.analyze
|
|
1261
|
+
}));
|
|
1262
|
+
}
|
|
1263
|
+
if (!ctx.nuxt.options.ssr) {
|
|
1264
|
+
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
|
+
}
|
|
1018
1266
|
}
|
|
1019
1267
|
|
|
1268
|
+
//#endregion
|
|
1269
|
+
//#region src/presets/node.ts
|
|
1020
1270
|
function node(ctx) {
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
maxAssetSize: Number.POSITIVE_INFINITY
|
|
1048
|
-
};
|
|
1271
|
+
ctx.config.target = "node";
|
|
1272
|
+
ctx.config.node = false;
|
|
1273
|
+
ctx.config.experiments.outputModule = true;
|
|
1274
|
+
ctx.config.output = {
|
|
1275
|
+
...ctx.config.output,
|
|
1276
|
+
chunkFilename: "[name].mjs",
|
|
1277
|
+
chunkFormat: "module",
|
|
1278
|
+
chunkLoading: "import",
|
|
1279
|
+
module: true,
|
|
1280
|
+
environment: {
|
|
1281
|
+
module: true,
|
|
1282
|
+
arrowFunction: true,
|
|
1283
|
+
bigIntLiteral: true,
|
|
1284
|
+
const: true,
|
|
1285
|
+
destructuring: true,
|
|
1286
|
+
dynamicImport: true,
|
|
1287
|
+
forOf: true
|
|
1288
|
+
},
|
|
1289
|
+
library: { type: "module" }
|
|
1290
|
+
};
|
|
1291
|
+
ctx.config.performance = {
|
|
1292
|
+
...ctx.config.performance,
|
|
1293
|
+
hints: false,
|
|
1294
|
+
maxEntrypointSize: Number.POSITIVE_INFINITY,
|
|
1295
|
+
maxAssetSize: Number.POSITIVE_INFINITY
|
|
1296
|
+
};
|
|
1049
1297
|
}
|
|
1050
1298
|
|
|
1299
|
+
//#endregion
|
|
1300
|
+
//#region src/configs/server.ts
|
|
1051
1301
|
const assetPattern = /\.(?:css|s[ca]ss|png|jpe?g|gif|svg|woff2?|eot|ttf|otf|webp|webm|mp4|ogv)(?:\?.*)?$/i;
|
|
1302
|
+
const VIRTUAL_RE = /^\0?virtual:(?:nuxt:)?/;
|
|
1052
1303
|
async function server(ctx) {
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1304
|
+
ctx.name = "server";
|
|
1305
|
+
ctx.isServer = true;
|
|
1306
|
+
await applyPresets(ctx, [
|
|
1307
|
+
nuxt,
|
|
1308
|
+
node,
|
|
1309
|
+
serverStandalone,
|
|
1310
|
+
serverPreset,
|
|
1311
|
+
serverPlugins
|
|
1312
|
+
]);
|
|
1062
1313
|
}
|
|
1063
1314
|
function serverPreset(ctx) {
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
};
|
|
1315
|
+
ctx.config.output.filename = "server.mjs";
|
|
1316
|
+
if (ctx.nuxt.options.sourcemap.server) {
|
|
1317
|
+
const prefix = ctx.nuxt.options.sourcemap.server === "hidden" ? "hidden-" : "";
|
|
1318
|
+
ctx.config.devtool = prefix + (ctx.isDev ? "cheap-module-source-map" : "source-map");
|
|
1319
|
+
} else ctx.config.devtool = false;
|
|
1320
|
+
ctx.config.optimization = {
|
|
1321
|
+
splitChunks: false,
|
|
1322
|
+
minimize: false
|
|
1323
|
+
};
|
|
1324
|
+
if (ctx.isDev) ctx.config.output.asyncChunks = false;
|
|
1075
1325
|
}
|
|
1076
1326
|
function serverStandalone(ctx) {
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1327
|
+
const inline = [
|
|
1328
|
+
"src/",
|
|
1329
|
+
"#app",
|
|
1330
|
+
"nuxt",
|
|
1331
|
+
"nuxt3",
|
|
1332
|
+
"nuxt-nightly",
|
|
1333
|
+
"!",
|
|
1334
|
+
"-!",
|
|
1335
|
+
"~",
|
|
1336
|
+
"@/",
|
|
1337
|
+
"#",
|
|
1338
|
+
...ctx.options.build.transpile
|
|
1339
|
+
];
|
|
1340
|
+
const external = new Set([
|
|
1341
|
+
"nitro/runtime",
|
|
1342
|
+
"#internal/nitro",
|
|
1343
|
+
"nitropack/runtime",
|
|
1344
|
+
"#shared",
|
|
1345
|
+
resolve(ctx.nuxt.options.rootDir, ctx.nuxt.options.dir.shared),
|
|
1346
|
+
...ctx.nuxt["~runtimeDependencies"] || []
|
|
1347
|
+
]);
|
|
1348
|
+
if (!ctx.nuxt.options.dev) {
|
|
1349
|
+
external.add("#internal/nuxt/paths");
|
|
1350
|
+
external.add("#internal/nuxt/app-config");
|
|
1351
|
+
external.add("#app-manifest");
|
|
1352
|
+
}
|
|
1353
|
+
if (!Array.isArray(ctx.config.externals)) return;
|
|
1354
|
+
const conditions = [
|
|
1355
|
+
ctx.nuxt.options.dev ? "development" : "production",
|
|
1356
|
+
"node",
|
|
1357
|
+
"import",
|
|
1358
|
+
"require"
|
|
1359
|
+
];
|
|
1360
|
+
ctx.config.externals.push(({ request, context }, cb) => {
|
|
1361
|
+
if (!request) return cb(void 0, false);
|
|
1362
|
+
if (external.has(request)) {
|
|
1363
|
+
const resolved = resolveModulePath(request, {
|
|
1364
|
+
from: context ? [context, ...ctx.nuxt.options.modulesDir].map((d) => directoryToURL(d)) : ctx.nuxt.options.modulesDir.map((d) => directoryToURL(d)),
|
|
1365
|
+
suffixes: ["", "index"],
|
|
1366
|
+
conditions,
|
|
1367
|
+
try: true
|
|
1368
|
+
});
|
|
1369
|
+
if (resolved && isAbsolute(resolved)) return cb(void 0, resolved);
|
|
1370
|
+
return cb(void 0, true);
|
|
1371
|
+
}
|
|
1372
|
+
if (request[0] === "." || isAbsolute(request) || inline.find((prefix) => typeof prefix === "string" && request.startsWith(prefix)) || assetPattern.test(request)) return cb(void 0, false);
|
|
1373
|
+
if (context && request && !request.startsWith("node:") && (isAbsolute(context) || VIRTUAL_RE.test(context))) try {
|
|
1374
|
+
const resolved = resolveModulePath(resolveAlias(normalize(request), ctx.nuxt.options.alias), {
|
|
1375
|
+
from: [parseNodeModulePath(context).dir || ctx.nuxt.options.rootDir, ...ctx.nuxt.options.modulesDir].map((d) => directoryToURL(d)),
|
|
1376
|
+
suffixes: ["", "index"],
|
|
1377
|
+
conditions,
|
|
1378
|
+
try: true
|
|
1379
|
+
});
|
|
1380
|
+
if (resolved && isAbsolute(resolved)) return cb(void 0, false);
|
|
1381
|
+
} catch {}
|
|
1382
|
+
return cb(void 0, true);
|
|
1383
|
+
});
|
|
1118
1384
|
}
|
|
1119
1385
|
function serverPlugins(ctx) {
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
}
|
|
1127
|
-
if (!ctx.nuxt.options.test && (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev)) {
|
|
1128
|
-
ctx.config.plugins.push(new TsCheckerPlugin({
|
|
1129
|
-
logger
|
|
1130
|
-
}));
|
|
1131
|
-
}
|
|
1386
|
+
ctx.config.plugins ||= [];
|
|
1387
|
+
if (ctx.userConfig.serverURLPolyfill) ctx.config.plugins.push(new webpack.ProvidePlugin({
|
|
1388
|
+
URL: [ctx.userConfig.serverURLPolyfill, "URL"],
|
|
1389
|
+
URLSearchParams: [ctx.userConfig.serverURLPolyfill, "URLSearchParams"]
|
|
1390
|
+
}));
|
|
1391
|
+
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 }));
|
|
1132
1392
|
}
|
|
1133
1393
|
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
await new Promise((resolve) => compiler?.close(resolve));
|
|
1172
|
-
}
|
|
1173
|
-
});
|
|
1174
|
-
if (nuxt.options.dev) {
|
|
1175
|
-
await Promise.all(compilers.map((c) => c && compile(c)));
|
|
1176
|
-
return;
|
|
1177
|
-
}
|
|
1178
|
-
for (const c of compilers) {
|
|
1179
|
-
if (c) {
|
|
1180
|
-
await compile(c);
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1394
|
+
//#endregion
|
|
1395
|
+
//#region src/webpack.ts
|
|
1396
|
+
const bundle = async (nuxt$1) => {
|
|
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);
|
|
1400
|
+
await applyPresets(ctx, preset);
|
|
1401
|
+
return ctx.config;
|
|
1402
|
+
}));
|
|
1403
|
+
/** Remove Nitro rollup plugin for handling dynamic imports from webpack chunks */
|
|
1404
|
+
if (!nuxt$1.options.dev) useNitro().hooks.hook("rollup:before", (_nitro, config) => {
|
|
1405
|
+
const plugins = config.plugins;
|
|
1406
|
+
const existingPlugin = plugins.findIndex((i) => i && "name" in i && i.name === "dynamic-require");
|
|
1407
|
+
if (existingPlugin >= 0) plugins.splice(existingPlugin, 1);
|
|
1408
|
+
});
|
|
1409
|
+
await nuxt$1.callHook(`${builder}:config`, webpackConfigs);
|
|
1410
|
+
const mfs = nuxt$1.options.dev ? createMFS() : null;
|
|
1411
|
+
const ssrStylesPlugin = nuxt$1.options.ssr && !nuxt$1.options.dev && nuxt$1.options.features.inlineStyles ? new SSRStylesPlugin(nuxt$1) : null;
|
|
1412
|
+
for (const config of webpackConfigs) {
|
|
1413
|
+
config.plugins.push(DynamicBasePlugin.webpack({ sourcemap: !!nuxt$1.options.sourcemap[config.name] }));
|
|
1414
|
+
if (config.name === "client" && nuxt$1.options.experimental.emitRouteChunkError && nuxt$1.options.builder !== "@nuxt/rspack-builder") config.plugins.push(new ChunkErrorPlugin());
|
|
1415
|
+
if (ssrStylesPlugin) config.plugins.push(ssrStylesPlugin);
|
|
1416
|
+
}
|
|
1417
|
+
await nuxt$1.callHook(`${builder}:configResolved`, webpackConfigs);
|
|
1418
|
+
const compilers = webpackConfigs.map((config) => {
|
|
1419
|
+
const compiler = webpack(config);
|
|
1420
|
+
if (nuxt$1.options.dev && compiler) compiler.outputFileSystem = mfs;
|
|
1421
|
+
return compiler;
|
|
1422
|
+
});
|
|
1423
|
+
nuxt$1.hook("close", async () => {
|
|
1424
|
+
for (const compiler of compilers) await new Promise((resolve$1) => compiler.close(resolve$1));
|
|
1425
|
+
});
|
|
1426
|
+
if (nuxt$1.options.dev) {
|
|
1427
|
+
await Promise.all(compilers.map((c) => compile(c)));
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
for (const c of compilers) await compile(c);
|
|
1183
1431
|
};
|
|
1184
1432
|
async function createDevMiddleware(compiler) {
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
}));
|
|
1210
|
-
return devMiddleware;
|
|
1433
|
+
const nuxt$1 = useNuxt();
|
|
1434
|
+
logger.debug("Creating webpack middleware...");
|
|
1435
|
+
const devMiddleware = webpackDevMiddleware(compiler, {
|
|
1436
|
+
publicPath: joinURL(nuxt$1.options.app.baseURL, nuxt$1.options.app.buildAssetsDir),
|
|
1437
|
+
outputFileSystem: compiler.outputFileSystem,
|
|
1438
|
+
stats: "none",
|
|
1439
|
+
...nuxt$1.options.webpack.devMiddleware
|
|
1440
|
+
});
|
|
1441
|
+
nuxt$1.hook("close", () => pify(devMiddleware.close.bind(devMiddleware))());
|
|
1442
|
+
const { client: _client, ...hotMiddlewareOptions } = nuxt$1.options.webpack.hotMiddleware || {};
|
|
1443
|
+
const hotMiddleware = webpackHotMiddleware(compiler, {
|
|
1444
|
+
log: false,
|
|
1445
|
+
heartbeat: 1e4,
|
|
1446
|
+
path: joinURL(nuxt$1.options.app.baseURL, "__webpack_hmr", compiler.options.name),
|
|
1447
|
+
...hotMiddlewareOptions
|
|
1448
|
+
});
|
|
1449
|
+
const devHandler = wdmToH3Handler(devMiddleware);
|
|
1450
|
+
await nuxt$1.callHook("server:devHandler", defineEventHandler(async (event) => {
|
|
1451
|
+
const body = await devHandler(event);
|
|
1452
|
+
if (body !== void 0) return body;
|
|
1453
|
+
const { req, res } = "runtime" in event ? event.runtime.node : event.node;
|
|
1454
|
+
await new Promise((resolve$1, reject) => hotMiddleware(req, res, (err) => err ? reject(err) : resolve$1()));
|
|
1455
|
+
}), { cors: () => true });
|
|
1456
|
+
return devMiddleware;
|
|
1211
1457
|
}
|
|
1212
|
-
function wdmToH3Handler(devMiddleware
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
};
|
|
1237
|
-
devMiddleware(req, res, (err) => {
|
|
1238
|
-
if (err) {
|
|
1239
|
-
reject(err);
|
|
1240
|
-
} else {
|
|
1241
|
-
resolve(void 0);
|
|
1242
|
-
}
|
|
1243
|
-
});
|
|
1244
|
-
});
|
|
1245
|
-
return body;
|
|
1246
|
-
});
|
|
1458
|
+
function wdmToH3Handler(devMiddleware) {
|
|
1459
|
+
return defineEventHandler(async (event) => {
|
|
1460
|
+
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") throw { status: 403 };
|
|
1462
|
+
event.context.webpack = {
|
|
1463
|
+
...event.context.webpack,
|
|
1464
|
+
devMiddleware: devMiddleware.context
|
|
1465
|
+
};
|
|
1466
|
+
return await new Promise((resolve$1, reject) => {
|
|
1467
|
+
res.stream = (stream) => {
|
|
1468
|
+
resolve$1(stream);
|
|
1469
|
+
};
|
|
1470
|
+
res.send = (data) => {
|
|
1471
|
+
resolve$1(data);
|
|
1472
|
+
};
|
|
1473
|
+
res.finish = (data) => {
|
|
1474
|
+
resolve$1(data);
|
|
1475
|
+
};
|
|
1476
|
+
devMiddleware(req, res, (err) => {
|
|
1477
|
+
if (err) reject(err);
|
|
1478
|
+
else resolve$1(void 0);
|
|
1479
|
+
});
|
|
1480
|
+
});
|
|
1481
|
+
});
|
|
1247
1482
|
}
|
|
1248
1483
|
async function compile(compiler) {
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1484
|
+
const nuxt$1 = useNuxt();
|
|
1485
|
+
await nuxt$1.callHook(`${builder}:compile`, {
|
|
1486
|
+
name: compiler.options.name,
|
|
1487
|
+
compiler
|
|
1488
|
+
});
|
|
1489
|
+
compiler.hooks.done.tap("load-resources", async (stats$1) => {
|
|
1490
|
+
await nuxt$1.callHook(`${builder}:compiled`, {
|
|
1491
|
+
name: compiler.options.name,
|
|
1492
|
+
compiler,
|
|
1493
|
+
stats: stats$1
|
|
1494
|
+
});
|
|
1495
|
+
});
|
|
1496
|
+
if (nuxt$1.options.dev) {
|
|
1497
|
+
const compilersWatching = [];
|
|
1498
|
+
nuxt$1.hook("close", async () => {
|
|
1499
|
+
await Promise.all(compilersWatching.map((watching) => watching && pify(watching.close.bind(watching))()));
|
|
1500
|
+
});
|
|
1501
|
+
if (compiler.options.name === "client") return new Promise((resolve$1, reject) => {
|
|
1502
|
+
compiler.hooks.done.tap("nuxt-dev", () => {
|
|
1503
|
+
resolve$1(null);
|
|
1504
|
+
});
|
|
1505
|
+
compiler.hooks.failed.tap("nuxt-errorlog", (err) => {
|
|
1506
|
+
reject(err);
|
|
1507
|
+
});
|
|
1508
|
+
createDevMiddleware(compiler).then((devMiddleware) => {
|
|
1509
|
+
if (devMiddleware.context.watching) compilersWatching.push(devMiddleware.context.watching);
|
|
1510
|
+
});
|
|
1511
|
+
});
|
|
1512
|
+
return new Promise((resolve$1, reject) => {
|
|
1513
|
+
const watching = compiler.watch(nuxt$1.options.watchers.webpack, (err) => {
|
|
1514
|
+
if (err) return reject(err);
|
|
1515
|
+
resolve$1(null);
|
|
1516
|
+
});
|
|
1517
|
+
compilersWatching.push(watching);
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
const stats = await new Promise((resolve$1, reject) => compiler.run((err, stats$1) => err ? reject(err) : resolve$1(stats$1)));
|
|
1521
|
+
if (stats.hasErrors()) {
|
|
1522
|
+
const error = /* @__PURE__ */ new Error("Nuxt build error");
|
|
1523
|
+
error.stack = stats.toString("errors-only");
|
|
1524
|
+
throw error;
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
function defineEventHandler(handler) {
|
|
1528
|
+
return Object.assign(handler, { __is_handler__: true });
|
|
1290
1529
|
}
|
|
1291
1530
|
|
|
1292
|
-
|
|
1531
|
+
//#endregion
|
|
1532
|
+
export { bundle };
|