@nuxt/webpack-builder-nightly 4.3.0-29450657.a9b0ebbb → 4.3.0-29454382.becfbee6
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/dist/index.mjs +474 -5
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -3,12 +3,18 @@ import { fromNodeMiddleware, defineEventHandler, handleCors, getRequestHeader, c
|
|
|
3
3
|
import webpackDevMiddleware from 'webpack-dev-middleware';
|
|
4
4
|
import webpackHotMiddleware from 'webpack-hot-middleware';
|
|
5
5
|
import { defu } from 'defu';
|
|
6
|
-
import { joinURL } from 'ufo';
|
|
7
|
-
import {
|
|
6
|
+
import { withTrailingSlash, parseURL, joinURL } from 'ufo';
|
|
7
|
+
import { resolveAlias, useNitro, logger, tryImportModule, directoryToURL, useNuxt } from '@nuxt/kit';
|
|
8
8
|
import { createUnplugin } from 'unplugin';
|
|
9
9
|
import MagicString from 'magic-string';
|
|
10
10
|
import { webpack, WebpackBarPlugin, builder, MiniCssExtractPlugin, TsCheckerPlugin } from '#builder';
|
|
11
|
-
import {
|
|
11
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
12
|
+
import { createRequire } from 'node:module';
|
|
13
|
+
import { pathToFileURL } from 'node:url';
|
|
14
|
+
import { isAbsolute, resolve, relative, join, basename, normalize } from 'pathe';
|
|
15
|
+
import { genArrayFromRaw, genObjectFromRawEntries, genString } from 'knitwork';
|
|
16
|
+
import { parse, compileStyle } from '@vue/compiler-sfc';
|
|
17
|
+
import { createHash } from 'node:crypto';
|
|
12
18
|
import { createFsFromVolume, Volume } from 'memfs';
|
|
13
19
|
import querystring from 'node:querystring';
|
|
14
20
|
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
|
|
@@ -17,7 +23,6 @@ import TimeFixPlugin from 'time-fix-plugin';
|
|
|
17
23
|
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin';
|
|
18
24
|
import escapeRegExp from 'escape-string-regexp';
|
|
19
25
|
import { isTest } from 'std-env';
|
|
20
|
-
import { genObjectFromRawEntries, genString } from 'knitwork';
|
|
21
26
|
import { EsbuildPlugin } from 'esbuild-loader';
|
|
22
27
|
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
23
28
|
import createResolver from 'postcss-import-resolver';
|
|
@@ -95,6 +100,434 @@ if (typeof ${ensureChunk} !== "undefined") {
|
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
102
|
|
|
103
|
+
const CSS_URL_RE = /url\((['"]?)(\/[^)]+?)\1\)/g;
|
|
104
|
+
const isVueFile = (id) => /\.vue(?:\?|$)/.test(id);
|
|
105
|
+
const isCSSLike = (name) => /\.(?:css|scss|sass|less|styl(?:us)?|postcss|pcss)(?:\?|$)/.test(name);
|
|
106
|
+
function normalizePath(nuxt, id) {
|
|
107
|
+
if (!id) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
111
|
+
const rel = relative(nuxt.options.srcDir, pathname);
|
|
112
|
+
if (rel.startsWith("..")) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return rel;
|
|
116
|
+
}
|
|
117
|
+
function resolveFilePath(id) {
|
|
118
|
+
if (!id) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
return parseURL(decodeURIComponent(pathToFileURL(id).href)).pathname || null;
|
|
122
|
+
}
|
|
123
|
+
function sanitizeStyleAssetName(rel) {
|
|
124
|
+
return rel.replace(/[\\/]/g, "_").replace(/\.{2,}/g, "_");
|
|
125
|
+
}
|
|
126
|
+
function normalizeCSSContent(css) {
|
|
127
|
+
return css.trim().replace(/(--[^:]+):\s*'([^']*)'/g, '$1:"$2"').replace(/:\s+/g, ":").replace(/\s*\{\s*/g, "{").replace(/;\s*\}/g, "}").replace(/\s*\}\s*/g, "}");
|
|
128
|
+
}
|
|
129
|
+
function extractVueStyles(filePath) {
|
|
130
|
+
try {
|
|
131
|
+
const src = readFileSync(filePath, "utf8");
|
|
132
|
+
const { descriptor } = parse(src, { filename: filePath });
|
|
133
|
+
const styles = [];
|
|
134
|
+
const scopeId = createHash("sha256").update(filePath).digest("hex").slice(0, 8);
|
|
135
|
+
for (let i = 0; i < descriptor.styles.length; i++) {
|
|
136
|
+
const style = descriptor.styles[i];
|
|
137
|
+
const result = compileStyle({
|
|
138
|
+
source: style.content,
|
|
139
|
+
filename: filePath,
|
|
140
|
+
id: `data-v-${scopeId}`,
|
|
141
|
+
scoped: style.scoped
|
|
142
|
+
});
|
|
143
|
+
if (!result.errors.length && result.code) {
|
|
144
|
+
styles.push(normalizeCSSContent(result.code));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return styles;
|
|
148
|
+
} catch {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
class SSRStylesPlugin {
|
|
153
|
+
nuxt;
|
|
154
|
+
clientCSSByIssuer = /* @__PURE__ */ new Map();
|
|
155
|
+
chunksWithInlinedCSS = /* @__PURE__ */ new Set();
|
|
156
|
+
globalCSSPaths = /* @__PURE__ */ new Set();
|
|
157
|
+
constructor(nuxt) {
|
|
158
|
+
this.nuxt = nuxt;
|
|
159
|
+
this.globalCSSPaths = this.resolveGlobalCSS();
|
|
160
|
+
nuxt.hook("build:manifest", (manifest) => {
|
|
161
|
+
for (const [id, chunk] of Object.entries(manifest)) {
|
|
162
|
+
if (chunk.isEntry && chunk.src) {
|
|
163
|
+
this.chunksWithInlinedCSS.add(chunk.src);
|
|
164
|
+
} else if (this.chunksWithInlinedCSS.has(id)) {
|
|
165
|
+
chunk.css &&= [];
|
|
166
|
+
}
|
|
167
|
+
if (chunk.css?.length) {
|
|
168
|
+
chunk.css = chunk.css.filter((cssPath) => {
|
|
169
|
+
for (const globalPath of this.globalCSSPaths) {
|
|
170
|
+
if (cssPath.includes(globalPath.split("/").pop() || "")) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return true;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
shouldInline(mod) {
|
|
181
|
+
const shouldInline = this.nuxt.options.features.inlineStyles;
|
|
182
|
+
if (typeof shouldInline === "boolean") {
|
|
183
|
+
return shouldInline;
|
|
184
|
+
}
|
|
185
|
+
return shouldInline(mod.identifier());
|
|
186
|
+
}
|
|
187
|
+
escapeTemplateLiteral(str) {
|
|
188
|
+
return str.replace(/[`\\$]/g, (m) => m === "$" ? "\\$" : `\\${m}`);
|
|
189
|
+
}
|
|
190
|
+
isBuildAsset(url) {
|
|
191
|
+
const buildDir = withTrailingSlash(this.nuxt.options.app.buildAssetsDir || "/_nuxt/");
|
|
192
|
+
return url.startsWith(buildDir);
|
|
193
|
+
}
|
|
194
|
+
isPublicAsset(url, nitro) {
|
|
195
|
+
const cleaned = url.replace(/[?#].*$/, "");
|
|
196
|
+
for (const dir of nitro.options.publicAssets) {
|
|
197
|
+
const base = withTrailingSlash(dir.baseURL || "/");
|
|
198
|
+
if (!url.startsWith(base)) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const path = cleaned.replace(base, withTrailingSlash(dir.dir));
|
|
202
|
+
if (existsSync(path)) {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
rewriteStyle(css, nitro) {
|
|
209
|
+
let changed = false;
|
|
210
|
+
let needsPublicAsset = false;
|
|
211
|
+
let needsBuildAsset = false;
|
|
212
|
+
let lastIndex = 0;
|
|
213
|
+
let out = "`";
|
|
214
|
+
for (const match of css.matchAll(CSS_URL_RE)) {
|
|
215
|
+
const index = match.index ?? 0;
|
|
216
|
+
const before = css.slice(lastIndex, index);
|
|
217
|
+
if (before) {
|
|
218
|
+
out += this.escapeTemplateLiteral(before);
|
|
219
|
+
}
|
|
220
|
+
const full = match[0];
|
|
221
|
+
const rawUrl = match[2] || "";
|
|
222
|
+
const stripped = rawUrl.replace(/[?#].*$/, "");
|
|
223
|
+
if (this.isPublicAsset(stripped, nitro)) {
|
|
224
|
+
needsPublicAsset = true;
|
|
225
|
+
changed = true;
|
|
226
|
+
out += "${publicAssetsURL(" + JSON.stringify(rawUrl) + ")}";
|
|
227
|
+
} else if (this.isBuildAsset(stripped)) {
|
|
228
|
+
needsBuildAsset = true;
|
|
229
|
+
changed = true;
|
|
230
|
+
out += "${buildAssetsURL(" + JSON.stringify(rawUrl) + ")}";
|
|
231
|
+
} else {
|
|
232
|
+
out += this.escapeTemplateLiteral(full);
|
|
233
|
+
}
|
|
234
|
+
lastIndex = index + full.length;
|
|
235
|
+
}
|
|
236
|
+
const tail = css.slice(lastIndex);
|
|
237
|
+
if (tail) {
|
|
238
|
+
out += this.escapeTemplateLiteral(tail);
|
|
239
|
+
}
|
|
240
|
+
out += "`";
|
|
241
|
+
return {
|
|
242
|
+
code: changed ? out : JSON.stringify(css),
|
|
243
|
+
needsPublicAsset,
|
|
244
|
+
needsBuildAsset
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
resolveGlobalCSS() {
|
|
248
|
+
const req = createRequire(this.nuxt.options.rootDir);
|
|
249
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
250
|
+
const entries = this.nuxt.options.css || [];
|
|
251
|
+
for (const entry of entries) {
|
|
252
|
+
const src = typeof entry === "string" ? entry : entry?.src;
|
|
253
|
+
if (!src) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
const path = this.resolveCSSRequest(src, req);
|
|
257
|
+
if (path) {
|
|
258
|
+
resolved.add(path);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return resolved;
|
|
262
|
+
}
|
|
263
|
+
resolveCSSRequest(request, req) {
|
|
264
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
265
|
+
const resolved = resolveAlias(request, this.nuxt.options.alias);
|
|
266
|
+
if (isAbsolute(resolved)) {
|
|
267
|
+
candidates.add(resolved);
|
|
268
|
+
} else {
|
|
269
|
+
candidates.add(resolve(this.nuxt.options.srcDir, resolved));
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
candidates.add(req.resolve(request));
|
|
273
|
+
} catch {
|
|
274
|
+
}
|
|
275
|
+
for (const candidate of candidates) {
|
|
276
|
+
const path = resolveFilePath(candidate);
|
|
277
|
+
if (path) {
|
|
278
|
+
return path;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
normalizeResourcePath(resource) {
|
|
284
|
+
if (!resource) {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
const withoutQuery = resource.split("?")[0];
|
|
288
|
+
return resolveFilePath(withoutQuery);
|
|
289
|
+
}
|
|
290
|
+
apply(compiler) {
|
|
291
|
+
if (this.nuxt.options.dev) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const isClient = compiler.options.name === "client";
|
|
295
|
+
const isServer = compiler.options.name === "server";
|
|
296
|
+
if (!isClient && !isServer) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
compiler.hooks.thisCompilation.tap("SSRStylesPlugin", (compilation) => {
|
|
300
|
+
this.collectCSS(compilation);
|
|
301
|
+
if (isClient) {
|
|
302
|
+
this.removeGlobalCSSFromClient(compilation);
|
|
303
|
+
}
|
|
304
|
+
if (isServer) {
|
|
305
|
+
this.emitServerStyles(compilation);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
emitServerStyles(compilation) {
|
|
310
|
+
const { webpack } = compilation.compiler;
|
|
311
|
+
const stage = webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE;
|
|
312
|
+
compilation.hooks.processAssets.tap({ name: "SSRStylesPlugin", stage }, () => {
|
|
313
|
+
const nitro = useNitro();
|
|
314
|
+
const collected = new Map(this.clientCSSByIssuer);
|
|
315
|
+
const entryModules = /* @__PURE__ */ new Set();
|
|
316
|
+
for (const entrypoint of compilation.entrypoints.values()) {
|
|
317
|
+
const primaryChunk = typeof entrypoint.getEntrypointChunk === "function" ? entrypoint.getEntrypointChunk() : void 0;
|
|
318
|
+
const chunks = primaryChunk ? [primaryChunk] : entrypoint.chunks;
|
|
319
|
+
for (const chunk of chunks) {
|
|
320
|
+
for (const mod of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
|
|
321
|
+
if ("resource" in mod && typeof mod.resource === "string") {
|
|
322
|
+
const resolved = resolveFilePath(mod.resource);
|
|
323
|
+
if (resolved) {
|
|
324
|
+
const rel = normalizePath(this.nuxt, resolved);
|
|
325
|
+
if (rel) {
|
|
326
|
+
entryModules.add(rel);
|
|
327
|
+
} else {
|
|
328
|
+
entryModules.add(resolved);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
for (const module of compilation.modules) {
|
|
336
|
+
const normal = module;
|
|
337
|
+
const resource = normal.resource;
|
|
338
|
+
if (!resource || !isVueFile(resource)) {
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
const rel = normalizePath(this.nuxt, resource);
|
|
342
|
+
if (!rel) {
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (collected.has(rel)) {
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const vueStyles = extractVueStyles(resolveFilePath(resource) || resource);
|
|
349
|
+
if (vueStyles.length) {
|
|
350
|
+
collected.set(rel, new Set(vueStyles));
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const emitted = {};
|
|
354
|
+
const rawSource = webpack.sources.RawSource;
|
|
355
|
+
for (const [rel, cssSet] of collected.entries()) {
|
|
356
|
+
if (!cssSet.size) {
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
const stylesArray = Array.from(cssSet);
|
|
360
|
+
const transformed = stylesArray.map((style) => this.rewriteStyle(style, nitro));
|
|
361
|
+
const needsPublicAssets = transformed.some((t) => t.needsPublicAsset);
|
|
362
|
+
const needsBuildAssets = transformed.some((t) => t.needsBuildAsset);
|
|
363
|
+
const imports = [];
|
|
364
|
+
if (needsPublicAssets || needsBuildAssets) {
|
|
365
|
+
const names = [];
|
|
366
|
+
if (needsBuildAssets) {
|
|
367
|
+
names.push("buildAssetsURL");
|
|
368
|
+
}
|
|
369
|
+
if (needsPublicAssets) {
|
|
370
|
+
names.push("publicAssetsURL");
|
|
371
|
+
}
|
|
372
|
+
imports.push(`import { ${names.join(", ")} } from '#internal/nuxt/paths'`);
|
|
373
|
+
}
|
|
374
|
+
const moduleSource = [
|
|
375
|
+
...imports,
|
|
376
|
+
`export default ${genArrayFromRaw(transformed.map((t) => t.code))}`
|
|
377
|
+
].filter(Boolean).join("\n");
|
|
378
|
+
const styleModuleName = `${sanitizeStyleAssetName(rel)}-styles.mjs`;
|
|
379
|
+
compilation.emitAsset(styleModuleName, new rawSource(moduleSource));
|
|
380
|
+
emitted[rel] = styleModuleName;
|
|
381
|
+
this.chunksWithInlinedCSS.add(rel);
|
|
382
|
+
}
|
|
383
|
+
const stylesSource = [
|
|
384
|
+
"const interopDefault = r => r.default || r || []",
|
|
385
|
+
`export default ${genObjectFromRawEntries(
|
|
386
|
+
Object.entries(emitted).map(([key, value]) => [key, `() => import('./${value}').then(interopDefault)`])
|
|
387
|
+
)}`
|
|
388
|
+
].join("\n");
|
|
389
|
+
compilation.emitAsset("styles.mjs", new rawSource(stylesSource));
|
|
390
|
+
const entryIds = Array.from(this.chunksWithInlinedCSS).filter((id) => entryModules.has(id));
|
|
391
|
+
nitro.options.virtual["#internal/nuxt/entry-ids.mjs"] = () => `export default ${JSON.stringify(entryIds)}`;
|
|
392
|
+
nitro.options._config.virtual ||= {};
|
|
393
|
+
nitro.options._config.virtual["#internal/nuxt/entry-ids.mjs"] = nitro.options.virtual["#internal/nuxt/entry-ids.mjs"];
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
findIssuerPath(compilation, mod) {
|
|
397
|
+
let issuer = compilation.moduleGraph.getIssuer(mod);
|
|
398
|
+
while (issuer) {
|
|
399
|
+
if ("resource" in issuer && typeof issuer.resource === "string") {
|
|
400
|
+
return issuer.resource;
|
|
401
|
+
}
|
|
402
|
+
issuer = compilation.moduleGraph.getIssuer(issuer);
|
|
403
|
+
}
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
removeGlobalCSSFromClient(compilation) {
|
|
407
|
+
const stage = 650;
|
|
408
|
+
compilation.hooks.processAssets.tap({ name: "SSRStylesPlugin:RemoveGlobalCSS", stage }, () => {
|
|
409
|
+
for (const chunk of compilation.chunks) {
|
|
410
|
+
if (chunk.name === "nuxt-global-css") {
|
|
411
|
+
const cssAssets = [];
|
|
412
|
+
for (const file of Array.from(chunk.files)) {
|
|
413
|
+
const filename = String(file);
|
|
414
|
+
if (isCSSLike(filename)) {
|
|
415
|
+
const asset = compilation.getAsset(filename);
|
|
416
|
+
const source = asset?.source;
|
|
417
|
+
const content = source && typeof source.source === "function" ? source.source() : null;
|
|
418
|
+
const text = typeof content === "string" ? content : content instanceof Buffer ? content.toString("utf8") : "";
|
|
419
|
+
if (text) {
|
|
420
|
+
cssAssets.push(text);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (cssAssets.length > 0) {
|
|
425
|
+
for (const mod of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
|
|
426
|
+
const issuerPath = this.findIssuerPath(compilation, mod) || ("resource" in mod && typeof mod.resource === "string" ? mod.resource : null);
|
|
427
|
+
const normalized = normalizePath(this.nuxt, issuerPath);
|
|
428
|
+
if (!normalized) {
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
const set = this.clientCSSByIssuer.get(normalized) || /* @__PURE__ */ new Set();
|
|
432
|
+
for (const css of cssAssets) {
|
|
433
|
+
set.add(normalizeCSSContent(css));
|
|
434
|
+
}
|
|
435
|
+
this.clientCSSByIssuer.set(normalized, set);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
for (const file of Array.from(chunk.files)) {
|
|
439
|
+
const filename = String(file);
|
|
440
|
+
if (isCSSLike(filename)) {
|
|
441
|
+
compilation.deleteAsset(filename);
|
|
442
|
+
chunk.files.delete(file);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
collectCSS(compilation) {
|
|
450
|
+
const { webpack } = compilation.compiler;
|
|
451
|
+
const isServer = compilation.compiler.options.name === "server";
|
|
452
|
+
const stage = isServer ? webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS : webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER;
|
|
453
|
+
const chunkCSSMeta = /* @__PURE__ */ new Map();
|
|
454
|
+
compilation.hooks.processAssets.tap({ name: "SSRStylesPlugin", stage }, () => {
|
|
455
|
+
const cssAssetsByChunk = /* @__PURE__ */ new Map();
|
|
456
|
+
for (const chunk of compilation.chunks) {
|
|
457
|
+
const cssAssets = [];
|
|
458
|
+
const chunkCSSFiles = [];
|
|
459
|
+
for (const file of chunk.files) {
|
|
460
|
+
if (!isCSSLike(file)) {
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
chunkCSSFiles.push(file);
|
|
464
|
+
const asset = compilation.getAsset(file);
|
|
465
|
+
const source = asset?.source;
|
|
466
|
+
const content = source && typeof source.source === "function" ? source.source() : null;
|
|
467
|
+
const text = typeof content === "string" ? content : content instanceof Buffer ? content.toString("utf8") : "";
|
|
468
|
+
if (text) {
|
|
469
|
+
cssAssets.push(text);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (chunkCSSFiles.length) {
|
|
473
|
+
const chunkCSSModules = Array.from(compilation.chunkGraph.getChunkModulesIterable(chunk));
|
|
474
|
+
chunkCSSMeta.set(chunk, { files: chunkCSSFiles, modules: chunkCSSModules });
|
|
475
|
+
}
|
|
476
|
+
if (cssAssets.length) {
|
|
477
|
+
cssAssetsByChunk.set(chunk, cssAssets);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
for (const [chunk, cssAssets] of cssAssetsByChunk) {
|
|
481
|
+
for (const mod of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
|
|
482
|
+
if (!this.shouldInline(mod)) {
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
const issuerPath = this.findIssuerPath(compilation, mod) || ("resource" in mod && typeof mod.resource === "string" ? mod.resource : null);
|
|
486
|
+
const normalized = normalizePath(this.nuxt, issuerPath);
|
|
487
|
+
if (!normalized) {
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
const set = this.clientCSSByIssuer.get(normalized) || /* @__PURE__ */ new Set();
|
|
491
|
+
for (const css of cssAssets) {
|
|
492
|
+
set.add(normalizeCSSContent(css));
|
|
493
|
+
}
|
|
494
|
+
this.clientCSSByIssuer.set(normalized, set);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
for (const mod of compilation.modules) {
|
|
498
|
+
if (!this.shouldInline(mod)) {
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
const issuerPath = this.findIssuerPath(compilation, mod);
|
|
502
|
+
const normalized = normalizePath(this.nuxt, issuerPath);
|
|
503
|
+
if (!normalized) {
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
const cssChunks = this.getModuleCSS(mod, compilation);
|
|
507
|
+
if (!cssChunks.length) {
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
const set = this.clientCSSByIssuer.get(normalized) || /* @__PURE__ */ new Set();
|
|
511
|
+
set.add(cssChunks.join("\n"));
|
|
512
|
+
this.clientCSSByIssuer.set(normalized, set);
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
getModuleCSS(mod, _compilation) {
|
|
517
|
+
const cssModule = mod;
|
|
518
|
+
const cssChunks = [];
|
|
519
|
+
if (mod.type === "css/mini-extract" && Array.isArray(cssModule.content)) {
|
|
520
|
+
for (const part of cssModule.content) {
|
|
521
|
+
const css = part?.[1];
|
|
522
|
+
if (css && typeof css === "string") {
|
|
523
|
+
cssChunks.push(normalizeCSSContent(css));
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return cssChunks;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
98
531
|
function createMFS() {
|
|
99
532
|
const fs = createFsFromVolume(new Volume());
|
|
100
533
|
const _fs = { ...fs };
|
|
@@ -1021,7 +1454,39 @@ function clientHMR(ctx) {
|
|
|
1021
1454
|
ctx.config.plugins ||= [];
|
|
1022
1455
|
ctx.config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
1023
1456
|
}
|
|
1024
|
-
function clientOptimization(
|
|
1457
|
+
function clientOptimization(ctx) {
|
|
1458
|
+
if (!ctx.nuxt.options.features.inlineStyles) {
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
const globalCSSPaths = /* @__PURE__ */ new Set();
|
|
1462
|
+
for (const css of ctx.options.css) {
|
|
1463
|
+
if (typeof css === "string") {
|
|
1464
|
+
const resolved = resolveAlias(css, ctx.options.alias);
|
|
1465
|
+
globalCSSPaths.add(normalize(resolved));
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
if (globalCSSPaths.size > 0) {
|
|
1469
|
+
ctx.config.optimization ||= {};
|
|
1470
|
+
ctx.config.optimization.splitChunks ||= {};
|
|
1471
|
+
ctx.config.optimization.splitChunks.cacheGroups ||= {};
|
|
1472
|
+
ctx.config.optimization.splitChunks.cacheGroups.nuxtGlobalCSS = {
|
|
1473
|
+
name: "nuxt-global-css",
|
|
1474
|
+
chunks: "all",
|
|
1475
|
+
enforce: true,
|
|
1476
|
+
test: (module) => {
|
|
1477
|
+
if (module.type !== "css/mini-extract") {
|
|
1478
|
+
return false;
|
|
1479
|
+
}
|
|
1480
|
+
const identifier = normalize(module.identifier());
|
|
1481
|
+
for (const globalPath of globalCSSPaths) {
|
|
1482
|
+
if (identifier.includes(globalPath)) {
|
|
1483
|
+
return true;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return false;
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1025
1490
|
}
|
|
1026
1491
|
function clientPlugins(ctx) {
|
|
1027
1492
|
if (!ctx.isDev && !ctx.nuxt.options.test && ctx.name === "client" && ctx.userConfig.analyze && (ctx.userConfig.analyze === true || ctx.userConfig.analyze.enabled)) {
|
|
@@ -1224,6 +1689,7 @@ const bundle = async (nuxt) => {
|
|
|
1224
1689
|
}
|
|
1225
1690
|
await nuxt.callHook(`${builder}:config`, webpackConfigs);
|
|
1226
1691
|
const mfs = nuxt.options.dev ? createMFS() : null;
|
|
1692
|
+
const ssrStylesPlugin = nuxt.options.ssr && !nuxt.options.dev && nuxt.options.features.inlineStyles ? new SSRStylesPlugin(nuxt) : null;
|
|
1227
1693
|
for (const config of webpackConfigs) {
|
|
1228
1694
|
config.plugins.push(DynamicBasePlugin.webpack({
|
|
1229
1695
|
sourcemap: !!nuxt.options.sourcemap[config.name]
|
|
@@ -1231,6 +1697,9 @@ const bundle = async (nuxt) => {
|
|
|
1231
1697
|
if (config.name === "client" && nuxt.options.experimental.emitRouteChunkError && nuxt.options.builder !== "@nuxt/rspack-builder") {
|
|
1232
1698
|
config.plugins.push(new ChunkErrorPlugin());
|
|
1233
1699
|
}
|
|
1700
|
+
if (ssrStylesPlugin) {
|
|
1701
|
+
config.plugins.push(ssrStylesPlugin);
|
|
1702
|
+
}
|
|
1234
1703
|
}
|
|
1235
1704
|
await nuxt.callHook(`${builder}:configResolved`, webpackConfigs);
|
|
1236
1705
|
const compilers = webpackConfigs.map((config) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/webpack-builder-nightly",
|
|
3
|
-
"version": "4.3.0-
|
|
3
|
+
"version": "4.3.0-29454382.becfbee6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/nuxt.git",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@nuxt/friendly-errors-webpack-plugin": "^2.6.0",
|
|
31
|
-
"@nuxt/kit": "npm:@nuxt/kit-nightly@4.3.0-
|
|
31
|
+
"@nuxt/kit": "npm:@nuxt/kit-nightly@4.3.0-29454382.becfbee6",
|
|
32
|
+
"@vue/compiler-sfc": "3.5.26",
|
|
32
33
|
"autoprefixer": "^10.4.23",
|
|
33
34
|
"css-loader": "^7.1.2",
|
|
34
35
|
"css-minimizer-webpack-plugin": "^7.0.4",
|
|
@@ -72,7 +73,7 @@
|
|
|
72
73
|
"webpackbar": "^7.0.0"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
|
-
"@nuxt/schema": "npm:@nuxt/schema-nightly@4.3.0-
|
|
76
|
+
"@nuxt/schema": "npm:@nuxt/schema-nightly@4.3.0-29454382.becfbee6",
|
|
76
77
|
"@rspack/core": "1.6.8",
|
|
77
78
|
"@types/webpack-bundle-analyzer": "4.7.0",
|
|
78
79
|
"@types/webpack-hot-middleware": "2.25.12",
|
|
@@ -81,7 +82,7 @@
|
|
|
81
82
|
"vue": "3.5.26"
|
|
82
83
|
},
|
|
83
84
|
"peerDependencies": {
|
|
84
|
-
"nuxt": "npm:nuxt-nightly@4.3.0-
|
|
85
|
+
"nuxt": "npm:nuxt-nightly@4.3.0-29454382.becfbee6",
|
|
85
86
|
"vue": "^3.3.4"
|
|
86
87
|
},
|
|
87
88
|
"engines": {
|