From a20f01fb1189da04272b41e2b5c0c7271cc7255f Mon Sep 17 00:00:00 2001 From: Jonathan Neal Date: Tue, 28 Feb 2023 17:45:06 -0500 Subject: [PATCH] feature: pass tsconfig to vite alias --- .changeset/strong-colts-study.md | 5 ++++ .../src/vite-plugin-config-alias/index.ts | 30 ++++--------------- 2 files changed, 10 insertions(+), 25 deletions(-) create mode 100644 .changeset/strong-colts-study.md diff --git a/.changeset/strong-colts-study.md b/.changeset/strong-colts-study.md new file mode 100644 index 0000000000000..a837a4e4e28c5 --- /dev/null +++ b/.changeset/strong-colts-study.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Pass config aliases directly to Vite alias diff --git a/packages/astro/src/vite-plugin-config-alias/index.ts b/packages/astro/src/vite-plugin-config-alias/index.ts index ab4547cc671aa..7eed8a9040b42 100644 --- a/packages/astro/src/vite-plugin-config-alias/index.ts +++ b/packages/astro/src/vite-plugin-config-alias/index.ts @@ -81,7 +81,6 @@ export default function configAliasVitePlugin({ }: { settings: AstroSettings; }): vite.PluginOption { - const { config } = settings; /** Aliases from the tsconfig.json or jsconfig.json configuration. */ const configAlias = getConfigAlias(settings); @@ -91,29 +90,10 @@ export default function configAliasVitePlugin({ return { name: 'astro:tsconfig-alias', enforce: 'pre', - async resolveId(sourceId: string, importer, options) { - /** Resolved ID conditionally handled by any other resolver. (this gives priority to all other resolvers) */ - const resolvedId = await this.resolve(sourceId, importer, { skipSelf: true, ...options }); - - // if any other resolver handles the file, return that resolution - if (resolvedId) return resolvedId; - - // conditionally resolve the source ID from any matching alias or baseUrl - for (const alias of configAlias) { - if (alias.find.test(sourceId)) { - /** Processed Source ID with our alias applied. */ - const aliasedSourceId = sourceId.replace(alias.find, alias.replacement); - - /** Resolved ID conditionally handled by any other resolver. (this also gives priority to all other resolvers) */ - const resolvedAliasedId = await this.resolve(aliasedSourceId, importer, { - skipSelf: true, - ...options, - }); - - // if the existing resolvers find the file, return that resolution - if (resolvedAliasedId) return resolvedAliasedId; - } - } - }, + config: () => ({ + resolve: { + alias: configAlias, + }, + }), }; }