Skip to content

Commit

Permalink
Throw friendly error if renderer provides viteConfig in a bad format
Browse files Browse the repository at this point in the history
  • Loading branch information
drwpow committed Oct 22, 2021
1 parent 2d1cd3c commit 8530a8f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ export async function createVite(inlineConfig: ViteConfigWithSSR, { astroConfig,
for (const name of astroConfig.renderers) {
try {
const { default: renderer } = await import(name);
if (renderer && typeof renderer.viteConfig === 'function') {
if (!renderer) continue;
// if a renderer provides viteConfig(), call it and pass in results
if (renderer.viteConfig) {
if (typeof renderer.viteConfig !== 'function') {
throw new Error(`${name}: viteConfig(options) must be a function! Got ${typeof renderer.viteConfig}.`);
}
const rendererConfig = await renderer.viteConfig({ mode: inlineConfig.mode, command: inlineConfig.mode === 'production' ? 'build' : 'serve' }); // is this command true?
viteConfig = vite.mergeConfig(viteConfig, rendererConfig) as vite.InlineConfig;
}
} catch (err) {
throw new Error(`${name}\n ${err}`);
throw new Error(`${name}: ${err}`);
}
}

Expand Down

0 comments on commit 8530a8f

Please sign in to comment.