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