From de4f483dfbeb74817ef1ffb989ba979f8906f0d8 Mon Sep 17 00:00:00 2001 From: bluwy Date: Fri, 26 May 2023 16:40:49 +0800 Subject: [PATCH] Improve docs --- packages/astro/src/core/build/internal.ts | 4 ++-- .../astro/src/core/build/plugins/plugin-css.ts | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/astro/src/core/build/internal.ts b/packages/astro/src/core/build/internal.ts index d25d35f4f512..d1e2404d6d8a 100644 --- a/packages/astro/src/core/build/internal.ts +++ b/packages/astro/src/core/build/internal.ts @@ -14,7 +14,7 @@ export interface BuildInternals { * components are the entrypoint instead. This map is used as a cache from the SSR * build so the client can pick up the same information and use the same chunk ids. */ - cssModuleToChunkId: Map; + cssModuleToChunkIdMap: Map; // A mapping of hoisted script ids back to the exact hoisted scripts it references hoistedScriptIdToHoistedMap: Map>; @@ -95,7 +95,7 @@ export function createBuildInternals(): BuildInternals { const hoistedScriptIdToPagesMap = new Map>(); return { - cssModuleToChunkId: new Map(), + cssModuleToChunkIdMap: new Map(), hoistedScriptIdToHoistedMap, hoistedScriptIdToPagesMap, entrySpecifierToBundleMap: new Map(), diff --git a/packages/astro/src/core/build/plugins/plugin-css.ts b/packages/astro/src/core/build/plugins/plugin-css.ts index 87dc563d0a1b..1cec972239d8 100644 --- a/packages/astro/src/core/build/plugins/plugin-css.ts +++ b/packages/astro/src/core/build/plugins/plugin-css.ts @@ -77,12 +77,14 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] { // This causes CSS to be built into shared chunks when used by multiple pages. if (isBuildableCSSRequest(id)) { // For client builds that has hydrated components as entrypoints, there's no way - // to crawl up and find the pages that use it. So we lookup the cache here to derive - // the same chunk id so they match up on build. - // Some modules may not exist in cache (e.g. `client:only` components), and that's okay. - // We can use Rollup's default chunk strategy instead. + // to crawl up and find the pages that use it. So we lookup the cache during SSR + // build (that has the pages information) to derive the same chunk id so they + // match up on build, making sure both builds has the CSS deduped. + // NOTE: Components that are only used with `client:only` may not exist in the cache + // and that's okay. We can use Rollup's default chunk strategy instead as these CSS + // are outside of the SSR build scope, which no dedupe is needed. if (options.target === 'client') { - return internals.cssModuleToChunkId.get(id)!; + return internals.cssModuleToChunkIdMap.get(id)!; } for (const [pageInfo] of walkParentInfos(id, { @@ -92,12 +94,12 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] { // Split delayed assets to separate modules // so they can be injected where needed const chunkId = createNameHash(id, [id]); - internals.cssModuleToChunkId.set(id, chunkId); + internals.cssModuleToChunkIdMap.set(id, chunkId); return chunkId; } } const chunkId = createNameForParentPages(id, meta); - internals.cssModuleToChunkId.set(id, chunkId); + internals.cssModuleToChunkIdMap.set(id, chunkId); return chunkId; } },