@nuxt/vite-builder-nightly 5.0.0-29807902.5022deff → 5.0.0-29807919.2cbde35e
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 +133 -77
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -894,6 +894,7 @@ function SSRStylesPlugin(nuxt) {
|
|
|
894
894
|
const entryIds = /* @__PURE__ */ new Set();
|
|
895
895
|
for (const [id, { cssIds, files, inBundle }] of Object.entries(cssMap)) {
|
|
896
896
|
if (!inBundle || !files.length) continue;
|
|
897
|
+
if (islandExtractedIds.has(id)) continue;
|
|
897
898
|
chunksWithInlinedCSS.add(id);
|
|
898
899
|
if (!cssIds) continue;
|
|
899
900
|
for (const cssId of cssIds) {
|
|
@@ -946,10 +947,124 @@ function SSRStylesPlugin(nuxt) {
|
|
|
946
947
|
const components = nuxt.apps.default.components || [];
|
|
947
948
|
const islands = components.filter((component) => component.island || component.mode === "server" && !components.some((c) => c.pascalName === component.pascalName && c.mode === "client"));
|
|
948
949
|
const islandPaths = new Set(islands.map((c) => c.filePath));
|
|
950
|
+
const ssrImporters = /* @__PURE__ */ new Map();
|
|
951
|
+
const islandExtractedIds = /* @__PURE__ */ new Set();
|
|
952
|
+
const deferredExtractions = /* @__PURE__ */ new Map();
|
|
949
953
|
const flattenPages = (pages) => pages?.flatMap((p) => [p, ...flattenPages(p.children)]) ?? [];
|
|
950
954
|
const serverPages = flattenPages(nuxt.apps.default.pages).filter(({ mode, file }) => mode === "server" && file);
|
|
951
955
|
const serverPagePaths = new Set(serverPages.map(({ file }) => file));
|
|
952
956
|
let entry;
|
|
957
|
+
const isIslandModule = (path) => islandPaths.has(path) || serverPagePaths.has(path);
|
|
958
|
+
/**
|
|
959
|
+
* Whether a module is reachable from an island. An island's CSS is only ever delivered
|
|
960
|
+
* inline in its response: there is no stylesheet link to fall back to, and a server-only
|
|
961
|
+
* component's CSS is absent from the client build entirely.
|
|
962
|
+
*/
|
|
963
|
+
const isIslandDescendant = (path) => {
|
|
964
|
+
const seen = /* @__PURE__ */ new Set();
|
|
965
|
+
const queue = [path];
|
|
966
|
+
while (queue.length) {
|
|
967
|
+
const current = queue.shift();
|
|
968
|
+
if (seen.has(current)) continue;
|
|
969
|
+
seen.add(current);
|
|
970
|
+
for (const importer of ssrImporters.get(current) ?? []) {
|
|
971
|
+
if (isIslandModule(importer)) return true;
|
|
972
|
+
queue.push(importer);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
return false;
|
|
976
|
+
};
|
|
977
|
+
/**
|
|
978
|
+
* Emit inline-style chunks for a module of the server build and record them in `cssMap`,
|
|
979
|
+
* so the renderer can deliver its CSS as `<style>` tags.
|
|
980
|
+
*/
|
|
981
|
+
async function extractInlineStyles(ctx, id, code, mayDefer = false) {
|
|
982
|
+
const { pathname, search } = parseModuleId(id);
|
|
983
|
+
if (!(id in clientCSSMap) && !isIslandModule(pathname) && !isVue(pathname)) return;
|
|
984
|
+
if (MACRO_QUERY_RE.test(search) || NUXT_COMPONENT_QUERY_RE.test(search)) return;
|
|
985
|
+
const isEntryModule = pathname === entry;
|
|
986
|
+
let islandExtracted = false;
|
|
987
|
+
if (!isEntryModule && !isIslandModule(pathname)) {
|
|
988
|
+
if (options.shouldInline === false || typeof options.shouldInline === "function" && !options.shouldInline(id)) {
|
|
989
|
+
if (!isIslandDescendant(pathname)) {
|
|
990
|
+
if (mayDefer) deferredExtractions.set(id, code);
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
islandExtracted = true;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
if (isEntryModule && options.shouldInline === false) return;
|
|
997
|
+
const relativeId = relativeToSrcDir(stripQuery(id));
|
|
998
|
+
if (islandExtracted) islandExtractedIds.add(relativeId);
|
|
999
|
+
const idMap = cssMap[relativeId] ||= { files: [] };
|
|
1000
|
+
const idCssIds = idMap.cssIds ||= /* @__PURE__ */ new Set();
|
|
1001
|
+
const emittedIds = /* @__PURE__ */ new Set();
|
|
1002
|
+
let chunkNamePrefix = chunkNamePrefixes.get(relativeId);
|
|
1003
|
+
if (chunkNamePrefix === void 0) {
|
|
1004
|
+
const baseName = filename$1(id) || "styles";
|
|
1005
|
+
chunkNamePrefix = baseName;
|
|
1006
|
+
for (let i = 2; usedChunkNamePrefixes.has(chunkNamePrefix); i++) chunkNamePrefix = `${baseName}-${i}`;
|
|
1007
|
+
usedChunkNamePrefixes.add(chunkNamePrefix);
|
|
1008
|
+
chunkNamePrefixes.set(relativeId, chunkNamePrefix);
|
|
1009
|
+
}
|
|
1010
|
+
let styleCtr = 0;
|
|
1011
|
+
const ids = clientCSSMap[id] || [];
|
|
1012
|
+
for (const file of ids) {
|
|
1013
|
+
if (isEntryModule && typeof options.shouldInline === "function" && !options.shouldInline(file)) continue;
|
|
1014
|
+
if (emittedIds.has(file)) continue;
|
|
1015
|
+
const fileInline = withInlineQuery(file);
|
|
1016
|
+
const resolved = await ctx.resolve(file) ?? await ctx.resolve(file, id);
|
|
1017
|
+
const res = await ctx.resolve(fileInline) ?? await ctx.resolve(fileInline, id);
|
|
1018
|
+
if (!resolved || !res) {
|
|
1019
|
+
if (!warnCache.has(file)) {
|
|
1020
|
+
warnCache.add(file);
|
|
1021
|
+
ctx.warn(`[nuxt] Cannot extract styles for \`${file}\`. Its styles will not be inlined when server-rendering.`);
|
|
1022
|
+
}
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
emittedIds.add(file);
|
|
1026
|
+
idCssIds.add(stripQuery(resolved.id));
|
|
1027
|
+
const resolvedInlineId = res.id;
|
|
1028
|
+
let ref = emittedFileRefs[resolvedInlineId];
|
|
1029
|
+
if (!ref) {
|
|
1030
|
+
ref = ctx.emitFile({
|
|
1031
|
+
type: "chunk",
|
|
1032
|
+
name: `${chunkNamePrefix}-styles-${++styleCtr}.mjs`,
|
|
1033
|
+
id: fileInline
|
|
1034
|
+
});
|
|
1035
|
+
emittedFileRefs[resolvedInlineId] = ref;
|
|
1036
|
+
}
|
|
1037
|
+
idMap.files.push(ref);
|
|
1038
|
+
}
|
|
1039
|
+
if (!SUPPORTED_FILES_RE.test(pathname) || STYLE_QUERY_RE$1.test(search) || isCSS(search)) return;
|
|
1040
|
+
for (const specifier of getStaticImportSpecifiers(ctx.parse(code))) {
|
|
1041
|
+
if (!IS_CSS_RE.test(specifier) && !STYLE_QUERY_RE$1.test(specifier)) continue;
|
|
1042
|
+
const resolved = await ctx.resolve(specifier, id);
|
|
1043
|
+
if (!resolved) continue;
|
|
1044
|
+
const resolvedIdInline = withInlineQuery(resolved.id);
|
|
1045
|
+
const res = await ctx.resolve(resolvedIdInline);
|
|
1046
|
+
if (!res) {
|
|
1047
|
+
if (!warnCache.has(resolved.id)) {
|
|
1048
|
+
warnCache.add(resolved.id);
|
|
1049
|
+
ctx.warn(`[nuxt] Cannot extract styles for \`${specifier}\`. Its styles will not be inlined when server-rendering.`);
|
|
1050
|
+
}
|
|
1051
|
+
continue;
|
|
1052
|
+
}
|
|
1053
|
+
if (emittedIds.has(resolved.id)) continue;
|
|
1054
|
+
idCssIds.add(stripQuery(resolved.id));
|
|
1055
|
+
const resolvedInlineId = res.id;
|
|
1056
|
+
let ref = emittedFileRefs[resolvedInlineId];
|
|
1057
|
+
if (!ref) {
|
|
1058
|
+
ref = ctx.emitFile({
|
|
1059
|
+
type: "chunk",
|
|
1060
|
+
name: `${chunkNamePrefix}-styles-${++styleCtr}.mjs`,
|
|
1061
|
+
id: resolvedIdInline
|
|
1062
|
+
});
|
|
1063
|
+
emittedFileRefs[resolvedInlineId] = ref;
|
|
1064
|
+
}
|
|
1065
|
+
idMap.files.push(ref);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
953
1068
|
return {
|
|
954
1069
|
name: "ssr-styles",
|
|
955
1070
|
config(config) {
|
|
@@ -1064,6 +1179,23 @@ function SSRStylesPlugin(nuxt) {
|
|
|
1064
1179
|
setBuildOutput("ssrStyles", () => [`export default ${genObjectFromRawEntries(envEntries)}`, `export const inlinedCSS = ${serializeInlinedCSSConditions()}`].join("\n"), nuxt);
|
|
1065
1180
|
}
|
|
1066
1181
|
},
|
|
1182
|
+
async buildEnd() {
|
|
1183
|
+
if (environment.name !== "ssr") return;
|
|
1184
|
+
const deferred = [...deferredExtractions];
|
|
1185
|
+
deferredExtractions.clear();
|
|
1186
|
+
await Promise.all(deferred.map(([id, code]) => extractInlineStyles(this, id, code)));
|
|
1187
|
+
},
|
|
1188
|
+
moduleParsed(info) {
|
|
1189
|
+
if (environment.name !== "ssr") return;
|
|
1190
|
+
const importerId = stripQuery(info.id);
|
|
1191
|
+
for (const imported of [...info.importedIds, ...info.dynamicallyImportedIds]) {
|
|
1192
|
+
const id = stripQuery(imported);
|
|
1193
|
+
if (id === importerId) continue;
|
|
1194
|
+
const importers = ssrImporters.get(id) ?? /* @__PURE__ */ new Set();
|
|
1195
|
+
ssrImporters.set(id, importers);
|
|
1196
|
+
importers.add(importerId);
|
|
1197
|
+
}
|
|
1198
|
+
},
|
|
1067
1199
|
renderChunk(_code, chunk) {
|
|
1068
1200
|
const isEntry = chunk.facadeModuleId === entry;
|
|
1069
1201
|
if (isEntry) clientCSSMap[chunk.facadeModuleId] ||= /* @__PURE__ */ new Set();
|
|
@@ -1114,83 +1246,7 @@ function SSRStylesPlugin(nuxt) {
|
|
|
1114
1246
|
}
|
|
1115
1247
|
return;
|
|
1116
1248
|
}
|
|
1117
|
-
|
|
1118
|
-
if (!(id in clientCSSMap) && !islandPaths.has(pathname) && !serverPagePaths.has(pathname) && !isVue(pathname)) return;
|
|
1119
|
-
if (MACRO_QUERY_RE.test(search) || NUXT_COMPONENT_QUERY_RE.test(search)) return;
|
|
1120
|
-
const isEntryModule = pathname === entry;
|
|
1121
|
-
if (!isEntryModule && !islandPaths.has(pathname) && !serverPagePaths.has(pathname)) {
|
|
1122
|
-
if (options.shouldInline === false || typeof options.shouldInline === "function" && !options.shouldInline(id)) return;
|
|
1123
|
-
}
|
|
1124
|
-
if (isEntryModule && options.shouldInline === false) return;
|
|
1125
|
-
const relativeId = relativeToSrcDir(stripQuery(id));
|
|
1126
|
-
const idMap = cssMap[relativeId] ||= { files: [] };
|
|
1127
|
-
const idCssIds = idMap.cssIds ||= /* @__PURE__ */ new Set();
|
|
1128
|
-
const emittedIds = /* @__PURE__ */ new Set();
|
|
1129
|
-
let chunkNamePrefix = chunkNamePrefixes.get(relativeId);
|
|
1130
|
-
if (chunkNamePrefix === void 0) {
|
|
1131
|
-
const baseName = filename$1(id) || "styles";
|
|
1132
|
-
chunkNamePrefix = baseName;
|
|
1133
|
-
for (let i = 2; usedChunkNamePrefixes.has(chunkNamePrefix); i++) chunkNamePrefix = `${baseName}-${i}`;
|
|
1134
|
-
usedChunkNamePrefixes.add(chunkNamePrefix);
|
|
1135
|
-
chunkNamePrefixes.set(relativeId, chunkNamePrefix);
|
|
1136
|
-
}
|
|
1137
|
-
let styleCtr = 0;
|
|
1138
|
-
const ids = clientCSSMap[id] || [];
|
|
1139
|
-
for (const file of ids) {
|
|
1140
|
-
if (isEntryModule && typeof options.shouldInline === "function" && !options.shouldInline(file)) continue;
|
|
1141
|
-
if (emittedIds.has(file)) continue;
|
|
1142
|
-
const fileInline = withInlineQuery(file);
|
|
1143
|
-
const resolved = await this.resolve(file) ?? await this.resolve(file, id);
|
|
1144
|
-
const res = await this.resolve(fileInline) ?? await this.resolve(fileInline, id);
|
|
1145
|
-
if (!resolved || !res) {
|
|
1146
|
-
if (!warnCache.has(file)) {
|
|
1147
|
-
warnCache.add(file);
|
|
1148
|
-
this.warn(`[nuxt] Cannot extract styles for \`${file}\`. Its styles will not be inlined when server-rendering.`);
|
|
1149
|
-
}
|
|
1150
|
-
continue;
|
|
1151
|
-
}
|
|
1152
|
-
emittedIds.add(file);
|
|
1153
|
-
idCssIds.add(stripQuery(resolved.id));
|
|
1154
|
-
const resolvedInlineId = res.id;
|
|
1155
|
-
let ref = emittedFileRefs[resolvedInlineId];
|
|
1156
|
-
if (!ref) {
|
|
1157
|
-
ref = this.emitFile({
|
|
1158
|
-
type: "chunk",
|
|
1159
|
-
name: `${chunkNamePrefix}-styles-${++styleCtr}.mjs`,
|
|
1160
|
-
id: fileInline
|
|
1161
|
-
});
|
|
1162
|
-
emittedFileRefs[resolvedInlineId] = ref;
|
|
1163
|
-
}
|
|
1164
|
-
idMap.files.push(ref);
|
|
1165
|
-
}
|
|
1166
|
-
if (!SUPPORTED_FILES_RE.test(pathname) || STYLE_QUERY_RE$1.test(search) || isCSS(search)) return;
|
|
1167
|
-
for (const specifier of getStaticImportSpecifiers(this.parse(code))) {
|
|
1168
|
-
if (!IS_CSS_RE.test(specifier) && !STYLE_QUERY_RE$1.test(specifier)) continue;
|
|
1169
|
-
const resolved = await this.resolve(specifier, id);
|
|
1170
|
-
if (!resolved) continue;
|
|
1171
|
-
const resolvedIdInline = withInlineQuery(resolved.id);
|
|
1172
|
-
const res = await this.resolve(resolvedIdInline);
|
|
1173
|
-
if (!res) {
|
|
1174
|
-
if (!warnCache.has(resolved.id)) {
|
|
1175
|
-
warnCache.add(resolved.id);
|
|
1176
|
-
this.warn(`[nuxt] Cannot extract styles for \`${specifier}\`. Its styles will not be inlined when server-rendering.`);
|
|
1177
|
-
}
|
|
1178
|
-
continue;
|
|
1179
|
-
}
|
|
1180
|
-
if (emittedIds.has(resolved.id)) continue;
|
|
1181
|
-
idCssIds.add(stripQuery(resolved.id));
|
|
1182
|
-
const resolvedInlineId = res.id;
|
|
1183
|
-
let ref = emittedFileRefs[resolvedInlineId];
|
|
1184
|
-
if (!ref) {
|
|
1185
|
-
ref = this.emitFile({
|
|
1186
|
-
type: "chunk",
|
|
1187
|
-
name: `${chunkNamePrefix}-styles-${++styleCtr}.mjs`,
|
|
1188
|
-
id: resolvedIdInline
|
|
1189
|
-
});
|
|
1190
|
-
emittedFileRefs[resolvedInlineId] = ref;
|
|
1191
|
-
}
|
|
1192
|
-
idMap.files.push(ref);
|
|
1193
|
-
}
|
|
1249
|
+
await extractInlineStyles(this, id, code, true);
|
|
1194
1250
|
}
|
|
1195
1251
|
}
|
|
1196
1252
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/vite-builder-nightly",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-29807919.2cbde35e",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/nuxt.git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@nuxt/kit": "npm:@nuxt/kit-nightly@5.0.0-
|
|
27
|
+
"@nuxt/kit": "npm:@nuxt/kit-nightly@5.0.0-29807919.2cbde35e",
|
|
28
28
|
"@vitejs/plugin-vue": "^6.0.8",
|
|
29
29
|
"clickable-path": "^0.1.0",
|
|
30
30
|
"consola": "^3.4.2",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@babel/plugin-proposal-decorators": "8.0.2",
|
|
53
53
|
"@babel/plugin-syntax-jsx": "8.0.1",
|
|
54
|
-
"@nuxt/schema": "npm:@nuxt/schema-nightly@5.0.0-
|
|
54
|
+
"@nuxt/schema": "npm:@nuxt/schema-nightly@5.0.0-29807919.2cbde35e",
|
|
55
55
|
"@vitejs/plugin-vue-jsx": "5.1.6",
|
|
56
56
|
"autoprefixer": "^10.5.4",
|
|
57
57
|
"cssnano": "^9.0.1",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@vitejs/plugin-vue-jsx": "^5.1.5",
|
|
72
72
|
"autoprefixer": "^10.4.27",
|
|
73
73
|
"cssnano": "^7.1.3 || ^8.0.0 || ^9.0.0",
|
|
74
|
-
"nuxt": "npm:nuxt-nightly@5.0.0-
|
|
74
|
+
"nuxt": "npm:nuxt-nightly@5.0.0-29807919.2cbde35e",
|
|
75
75
|
"rollup-plugin-visualizer": "^6.0.0 || ^7.0.1",
|
|
76
76
|
"vue": "^3.3.4"
|
|
77
77
|
},
|