mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
fix: handle error at load for apps
This commit is contained in:
parent
c7dbb9d5c0
commit
df9e98a8c4
1 changed files with 11 additions and 2 deletions
|
@ -25,9 +25,18 @@ export default function astroDevToolbar({ settings }: AstroPluginOptions): vite.
|
|||
return `
|
||||
export const loadDevToolbarApps = async () => {
|
||||
return [${settings.devToolbarApps
|
||||
.map((plugin) => `(await import(${JSON.stringify(plugin)})).default`)
|
||||
.join(',')}];
|
||||
.map((plugin) => `await safeLoadPlugin(${JSON.stringify(plugin)})`)
|
||||
.join(',')}].filter(app => app !== undefined));
|
||||
};
|
||||
|
||||
async function safeLoadPlugin(entrypoint) {
|
||||
try {
|
||||
return (await import(entrypoint)).default;
|
||||
} catch (err) {
|
||||
console.error("Failed to load dev toolbar app from", entrypoint, err);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
`;
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue