Fix alias plugin causing CSS ordering issue (#8592)

This commit is contained in:
Bjorn Lu 2023-09-20 17:45:11 +08:00 committed by GitHub
parent c49e865f4f
commit 70f2a80039
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix alias plugin causing CSS ordering issue

View file

@ -70,7 +70,8 @@ export default function configAliasVitePlugin({
const plugin: VitePlugin = { const plugin: VitePlugin = {
name: 'astro:tsconfig-alias', name: 'astro:tsconfig-alias',
enforce: 'pre', // use post to only resolve ids that all other plugins before it can't
enforce: 'post',
configResolved(config) { configResolved(config) {
patchCreateResolver(config, plugin); patchCreateResolver(config, plugin);
}, },
@ -100,7 +101,7 @@ export default function configAliasVitePlugin({
* *
* Vite may simplify this soon: https://github.com/vitejs/vite/pull/10555 * 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; const _createResolver = config.createResolver;
// @ts-expect-error override readonly property intentionally // @ts-expect-error override readonly property intentionally
config.createResolver = function (...args1: any) { config.createResolver = function (...args1: any) {
@ -124,15 +125,16 @@ function patchCreateResolver(config: ResolvedConfig, prePlugin: VitePlugin) {
ssr, ssr,
}; };
const result = await resolver.apply(_createResolver, args2);
if (result) return result;
// @ts-expect-error resolveId exists // @ts-expect-error resolveId exists
const resolved = await prePlugin.resolveId.apply(fakePluginContext, [ const resolved = await postPlugin.resolveId.apply(fakePluginContext, [
id, id,
importer, importer,
fakeResolveIdOpts, fakeResolveIdOpts,
]); ]);
if (resolved) return resolved; if (resolved) return resolved;
return resolver.apply(_createResolver, args2);
}; };
}; };
} }