diff --git a/packages/astro/src/vite-plugin-css/index.ts b/packages/astro/src/vite-plugin-css/index.ts index 6ee1e0bf1f4f..5c22a3c0b162 100644 --- a/packages/astro/src/vite-plugin-css/index.ts +++ b/packages/astro/src/vite-plugin-css/index.ts @@ -19,7 +19,9 @@ const ASTRO_CSS_EXTENSION_POST_PATTERN = '@_@'; * Inverse function of getVirtualModulePageName(). */ function getComponentFromVirtualModuleCssName(virtualModulePrefix: string, id: string): string { - return id.slice(virtualModulePrefix.length).replace(new RegExp(ASTRO_CSS_EXTENSION_POST_PATTERN, 'g'), '.'); + return id + .slice(virtualModulePrefix.length) + .replace(new RegExp(ASTRO_CSS_EXTENSION_POST_PATTERN, 'g'), '.'); } /** @@ -56,7 +58,10 @@ export function astroDevCssPlugin({ routesList, command }: AstroVitePluginOption }; } if (id.startsWith(RESOLVED_MODULE_DEV_CSS_PREFIX)) { - const componentPath = getComponentFromVirtualModuleCssName(RESOLVED_MODULE_DEV_CSS_PREFIX, id); + const componentPath = getComponentFromVirtualModuleCssName( + RESOLVED_MODULE_DEV_CSS_PREFIX, + id, + ); const cssSet = routeCssMap.get(componentPath) || new Set(); return { code: `export const css = new Set(${JSON.stringify(Array.from(cssSet.values()))})`, diff --git a/packages/astro/src/vite-plugin-pages/util.ts b/packages/astro/src/vite-plugin-pages/util.ts index 4ca1dc3815a7..8767cfb7d9c4 100644 --- a/packages/astro/src/vite-plugin-pages/util.ts +++ b/packages/astro/src/vite-plugin-pages/util.ts @@ -1,4 +1,4 @@ -import { extname } from 'node:path'; +import { fileExtension } from '@astrojs/internal-helpers/path'; // This is an arbitrary string that we use to replace the dot of the extension. const ASTRO_PAGE_EXTENSION_POST_PATTERN = '@_@'; @@ -10,7 +10,7 @@ const ASTRO_PAGE_EXTENSION_POST_PATTERN = '@_@'; * @param path Page component path */ export function getVirtualModulePageName(virtualModulePrefix: string, path: string): string { - const extension = extname(path); + const extension = fileExtension(path); return ( virtualModulePrefix + (extension.startsWith('.')