From 9df3571d96b937c49c9479ac439e3479f2e9b94c Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 15 Dec 2021 08:33:52 -0600 Subject: [PATCH] attempt: externalize resolution with "pre" --- packages/astro/src/core/create-vite.ts | 2 ++ .../astro/src/vite-plugin-external/index.ts | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 packages/astro/src/vite-plugin-external/index.ts diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 8d87620af..03e53b34e 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -6,6 +6,7 @@ import { builtinModules, createRequire } from 'module'; import { fileURLToPath } from 'url'; import vite from './vite.js'; import astroVitePlugin from '../vite-plugin-astro/index.js'; +import externalVitePlugin from '../vite-plugin-external/index.js'; import astroPostprocessVitePlugin from '../vite-plugin-astro-postprocess/index.js'; import configAliasVitePlugin from '../vite-plugin-config-alias/index.js'; import markdownVitePlugin from '../vite-plugin-markdown/index.js'; @@ -54,6 +55,7 @@ export async function createVite(inlineConfig: ViteConfigWithSSR, { astroConfig, exclude: [...ALWAYS_EXTERNAL], }, plugins: [ + externalVitePlugin({ config: astroConfig }), configAliasVitePlugin({ config: astroConfig }), astroVitePlugin({ config: astroConfig, devServer, logging }), markdownVitePlugin({ config: astroConfig, devServer }), diff --git a/packages/astro/src/vite-plugin-external/index.ts b/packages/astro/src/vite-plugin-external/index.ts new file mode 100644 index 000000000..a14bcfe7a --- /dev/null +++ b/packages/astro/src/vite-plugin-external/index.ts @@ -0,0 +1,20 @@ +import type vite from '../core/vite'; +import type { AstroConfig } from '../@types/astro'; + +interface AstroPluginOptions { + config: AstroConfig; +} + +/** Transform .astro files for Vite */ +export default function astro({ config }: AstroPluginOptions): vite.Plugin { + return { + name: '@astrojs/vite-plugin-external', + enforce: 'pre', + resolveId(source, importer, options) { + if (source.includes('.config.')) { + console.log({ source, importer, options }); + } + return null; + } + }; +}