From cad09a40700251422a0bbf913123b5635e4861fe Mon Sep 17 00:00:00 2001 From: bluwy Date: Mon, 18 Sep 2023 19:13:52 +0800 Subject: [PATCH 1/3] Fix alias plugin causing CSS ordering issue --- .changeset/serious-wolves-breathe.md | 5 +++++ packages/astro/src/core/create-vite.ts | 4 ++-- packages/astro/src/vite-plugin-config-alias/index.ts | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .changeset/serious-wolves-breathe.md diff --git a/.changeset/serious-wolves-breathe.md b/.changeset/serious-wolves-breathe.md new file mode 100644 index 000000000000..cc1fcc420316 --- /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/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 5848bbe53214..f3b20c4f3f0d 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -111,8 +111,6 @@ export async function createVite( exclude: ['astro', 'node-fetch'], }, plugins: [ - configAliasVitePlugin({ settings }), - astroLoadFallbackPlugin({ fs, root: settings.config.root }), astroVitePlugin({ settings, logger }), astroScriptsPlugin({ settings }), // The server plugin is for dev only and having it run during the build causes @@ -134,6 +132,8 @@ export async function createVite( vitePluginSSRManifest(), astroAssetsPlugin({ settings, logger, mode }), astroTransitions(), + configAliasVitePlugin({ settings }), + astroLoadFallbackPlugin({ fs, root: settings.config.root }), ], publicDir: fileURLToPath(settings.config.publicDir), root: fileURLToPath(settings.config.root), diff --git a/packages/astro/src/vite-plugin-config-alias/index.ts b/packages/astro/src/vite-plugin-config-alias/index.ts index 8b8535af988c..25c20a033f4d 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); }, From 1d224c79d67ae6489780c7b8feb34aec2e93f5ad Mon Sep 17 00:00:00 2001 From: bluwy Date: Mon, 18 Sep 2023 19:21:55 +0800 Subject: [PATCH 2/3] Update patchCreateResolver --- packages/astro/src/vite-plugin-config-alias/index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/astro/src/vite-plugin-config-alias/index.ts b/packages/astro/src/vite-plugin-config-alias/index.ts index 25c20a033f4d..e91197a8e866 100644 --- a/packages/astro/src/vite-plugin-config-alias/index.ts +++ b/packages/astro/src/vite-plugin-config-alias/index.ts @@ -101,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) { @@ -125,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); }; }; } From 97b31e874c30c27dd291dcf505b7a7a69c98ec75 Mon Sep 17 00:00:00 2001 From: bluwy Date: Mon, 18 Sep 2023 22:13:15 +0800 Subject: [PATCH 3/3] Revert order for now --- packages/astro/src/core/create-vite.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index f3b20c4f3f0d..5848bbe53214 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -111,6 +111,8 @@ export async function createVite( exclude: ['astro', 'node-fetch'], }, plugins: [ + configAliasVitePlugin({ settings }), + astroLoadFallbackPlugin({ fs, root: settings.config.root }), astroVitePlugin({ settings, logger }), astroScriptsPlugin({ settings }), // The server plugin is for dev only and having it run during the build causes @@ -132,8 +134,6 @@ export async function createVite( vitePluginSSRManifest(), astroAssetsPlugin({ settings, logger, mode }), astroTransitions(), - configAliasVitePlugin({ settings }), - astroLoadFallbackPlugin({ fs, root: settings.config.root }), ], publicDir: fileURLToPath(settings.config.publicDir), root: fileURLToPath(settings.config.root),