fix: only add to ssr.noExternal if present in project
This commit is contained in:
parent
08820f17ff
commit
e3c4baa4f5
1 changed files with 16 additions and 1 deletions
|
@ -14,6 +14,7 @@ import astroIntegrationsContainerPlugin from '../vite-plugin-integrations-contai
|
|||
import jsxVitePlugin from '../vite-plugin-jsx/index.js';
|
||||
import markdownVitePlugin from '../vite-plugin-markdown/index.js';
|
||||
import astroScriptsPlugin from '../vite-plugin-scripts/index.js';
|
||||
import { resolveDependency } from './util.js';
|
||||
|
||||
// note: ssr is still an experimental API hence the type omission from `vite`
|
||||
export type ViteConfigWithSSR = vite.InlineConfig & { ssr?: vite.SSROptions };
|
||||
|
@ -31,6 +32,20 @@ const ALWAYS_NOEXTERNAL = new Set([
|
|||
'astro/components',
|
||||
]);
|
||||
|
||||
function getSsrNoExternalDeps(projectRoot: URL): string[] {
|
||||
let noExternalDeps = []
|
||||
for (const dep of ALWAYS_NOEXTERNAL) {
|
||||
try {
|
||||
resolveDependency(dep, projectRoot)
|
||||
noExternalDeps.push(dep)
|
||||
} catch {
|
||||
// ignore dependency if *not* installed / present in your project
|
||||
// prevents hard error from Vite!
|
||||
}
|
||||
}
|
||||
return noExternalDeps
|
||||
}
|
||||
|
||||
/** Return a common starting point for all Vite actions */
|
||||
export async function createVite(
|
||||
commandConfig: ViteConfigWithSSR,
|
||||
|
@ -103,7 +118,7 @@ export async function createVite(
|
|||
conditions: ['astro'],
|
||||
},
|
||||
ssr: {
|
||||
noExternal: [...ALWAYS_NOEXTERNAL],
|
||||
noExternal: getSsrNoExternalDeps(astroConfig.root),
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue