diff --git a/.changeset/serious-wolves-breathe.md b/.changeset/serious-wolves-breathe.md new file mode 100644 index 000000000..cc1fcc420 --- /dev/null +++ b/.changeset/serious-wolves-breathe.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix alias plugin causing CSS ordering issue diff --git a/packages/astro/src/vite-plugin-config-alias/index.ts b/packages/astro/src/vite-plugin-config-alias/index.ts index 8b8535af9..e91197a8e 100644 --- a/packages/astro/src/vite-plugin-config-alias/index.ts +++ b/packages/astro/src/vite-plugin-config-alias/index.ts @@ -70,7 +70,8 @@ export default function configAliasVitePlugin({ const plugin: VitePlugin = { name: 'astro:tsconfig-alias', - enforce: 'pre', + // use post to only resolve ids that all other plugins before it can't + enforce: 'post', configResolved(config) { patchCreateResolver(config, plugin); }, @@ -100,7 +101,7 @@ export default function configAliasVitePlugin({ * * Vite may simplify this soon: https://github.com/vitejs/vite/pull/10555 */ -function patchCreateResolver(config: ResolvedConfig, prePlugin: VitePlugin) { +function patchCreateResolver(config: ResolvedConfig, postPlugin: VitePlugin) { const _createResolver = config.createResolver; // @ts-expect-error override readonly property intentionally config.createResolver = function (...args1: any) { @@ -124,15 +125,16 @@ function patchCreateResolver(config: ResolvedConfig, prePlugin: VitePlugin) { ssr, }; + const result = await resolver.apply(_createResolver, args2); + if (result) return result; + // @ts-expect-error resolveId exists - const resolved = await prePlugin.resolveId.apply(fakePluginContext, [ + const resolved = await postPlugin.resolveId.apply(fakePluginContext, [ id, importer, fakeResolveIdOpts, ]); if (resolved) return resolved; - - return resolver.apply(_createResolver, args2); }; }; }