Skip to content

Commit

Permalink
Fix alias plugin causing CSS ordering issue (#8592)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Sep 20, 2023
1 parent c49e865 commit 70f2a80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-wolves-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix alias plugin causing CSS ordering issue
12 changes: 7 additions & 5 deletions packages/astro/src/vite-plugin-config-alias/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
};
};
}
Expand Down

0 comments on commit 70f2a80

Please sign in to comment.