@nuxt/vite-builder-nightly 5.0.0-29776938.e673c552 → 5.0.0-29778218.1397500a

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.
Files changed (2) hide show
  1. package/dist/index.mjs +48 -6
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -789,6 +789,46 @@ function SSRStylesPlugin(nuxt) {
789
789
  for (const cssId of sources) if (!isInlinedForEveryImporter(cssId)) return false;
790
790
  return true;
791
791
  };
792
+ const inlinedCSSConditions = /* @__PURE__ */ new Map();
793
+ const serializeInlinedCSSConditions = () => JSON.stringify(Object.fromEntries(inlinedCSSConditions));
794
+ /**
795
+ * Decide how a droppable CSS file should be handled, recording a render-time
796
+ * condition when some of its sources are only inlined for components that may
797
+ * not be server-rendered on a given request (for example a component used
798
+ * inside `<ClientOnly>` on one route and server-rendered on another).
799
+ *
800
+ * Returns `true` when the link can be removed from the manifest outright,
801
+ * i.e. every CSS source is inlined for an entry module, which is always in
802
+ * `ssrContext.modules`.
803
+ */
804
+ const dropCSSFile = (file, entryIds) => {
805
+ const cssFile = basename(file);
806
+ const sources = cssSourcesByCSSFile.get(cssFile);
807
+ const conditions = [];
808
+ for (const cssId of sources) {
809
+ const consumers = inlinedCSSConsumers.get(cssId);
810
+ if (!consumers?.size) continue;
811
+ let alwaysRendered = false;
812
+ for (const consumer of consumers) if (entryIds.has(consumer)) {
813
+ alwaysRendered = true;
814
+ break;
815
+ }
816
+ if (!alwaysRendered) conditions.push(Array.from(consumers));
817
+ }
818
+ if (!conditions.length) return true;
819
+ inlinedCSSConditions.set(cssFile, conditions);
820
+ return false;
821
+ };
822
+ /**
823
+ * Record a render-time condition for CSS files attributed to a single
824
+ * component, used for rolldown-generated chunks whose CSS is matched to the
825
+ * component by filename rather than through the module graph.
826
+ */
827
+ const dropComponentCSSFile = (file, componentId, entryIds) => {
828
+ if (entryIds.has(componentId)) return true;
829
+ inlinedCSSConditions.set(basename(file), [[componentId]]);
830
+ return false;
831
+ };
792
832
  nuxt.hook("build:manifest", (manifest) => {
793
833
  const entryIds = /* @__PURE__ */ new Set();
794
834
  for (const [id, { cssIds, files, inBundle }] of Object.entries(cssMap)) {
@@ -801,24 +841,26 @@ function SSRStylesPlugin(nuxt) {
801
841
  consumers.add(id);
802
842
  }
803
843
  }
844
+ for (const id of chunksWithInlinedCSS) {
845
+ const chunk = manifest[id];
846
+ if (chunk?.isEntry && chunk.src) entryIds.add(chunk.src);
847
+ }
804
848
  for (const id of chunksWithInlinedCSS) {
805
849
  const chunk = manifest[id];
806
850
  if (!chunk) continue;
807
- if (chunk.isEntry && chunk.src) entryIds.add(chunk.src);
808
- else chunk.css &&= chunk.css.filter((file) => !isDroppableCSSFile(file));
809
851
  if (chunk.imports && chunk.src) {
810
852
  const componentBaseName = filename(chunk.src);
811
853
  for (const imp of chunk.imports) {
812
854
  const imported = manifest[imp];
813
855
  if (imported?.css?.length && !imported.isEntry && !imported.src) {
814
- if (imported.css.every((css) => css.startsWith(componentBaseName + "."))) imported.css = [];
856
+ if (imported.css.every((css) => css.startsWith(componentBaseName + "."))) imported.css = imported.css.filter((file) => !dropComponentCSSFile(file, id, entryIds));
815
857
  }
816
858
  }
817
859
  }
818
860
  }
819
861
  for (const chunk of Object.values(manifest)) {
820
862
  if (!chunk.css?.length) continue;
821
- chunk.css = chunk.css.filter((file) => !isDroppableCSSFile(file));
863
+ chunk.css = chunk.css.filter((file) => !(isDroppableCSSFile(file) && dropCSSFile(file, entryIds)));
822
864
  }
823
865
  setBuildOutput("entryIds", () => `export default ${JSON.stringify(Array.from(entryIds))}`, nuxt);
824
866
  });
@@ -867,7 +909,7 @@ function SSRStylesPlugin(nuxt) {
867
909
  buildStart() {
868
910
  if (!envApi && this.environment.name === "ssr") {
869
911
  const stylesPath = resolve(this.environment.config.build.outDir, "styles.mjs");
870
- setBuildOutput("ssrStyles", () => `export { default } from ${JSON.stringify(pathToFileURL(stylesPath).href)}`, nuxt);
912
+ setBuildOutput("ssrStyles", () => [`export { default } from ${JSON.stringify(pathToFileURL(stylesPath).href)}`, `export const inlinedCSS = ${serializeInlinedCSSConditions()}`].join("\n"), nuxt);
871
913
  }
872
914
  },
873
915
  resolveId: {
@@ -958,7 +1000,7 @@ function SSRStylesPlugin(nuxt) {
958
1000
  });
959
1001
  if (envApi) {
960
1002
  const envEntries = Object.entries(emitted).map(([key, value]) => [key, `() => import('./${basename(this.getFileName(value))}').then(r => r.default || r || [])`]);
961
- setBuildOutput("ssrStyles", () => `export default ${genObjectFromRawEntries(envEntries)}`, nuxt);
1003
+ setBuildOutput("ssrStyles", () => [`export default ${genObjectFromRawEntries(envEntries)}`, `export const inlinedCSS = ${serializeInlinedCSSConditions()}`].join("\n"), nuxt);
962
1004
  }
963
1005
  },
964
1006
  renderChunk(_code, chunk) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/vite-builder-nightly",
3
- "version": "5.0.0-29776938.e673c552",
3
+ "version": "5.0.0-29778218.1397500a",
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-29776938.e673c552",
27
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@5.0.0-29778218.1397500a",
28
28
  "@vitejs/plugin-vue": "^6.0.8",
29
29
  "clickable-path": "^0.0.1",
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-29776938.e673c552",
54
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@5.0.0-29778218.1397500a",
55
55
  "@vitejs/plugin-vue-jsx": "5.1.6",
56
56
  "autoprefixer": "^10.5.4",
57
57
  "cssnano": "^8.0.2",
@@ -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",
74
- "nuxt": "npm:nuxt-nightly@5.0.0-29776938.e673c552",
74
+ "nuxt": "npm:nuxt-nightly@5.0.0-29778218.1397500a",
75
75
  "rollup-plugin-visualizer": "^6.0.0 || ^7.0.1",
76
76
  "vue": "^3.3.4"
77
77
  },