0
Fork 0
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:
Princesseuh 2024-01-15 11:40:31 -05:00
parent c7dbb9d5c0
commit df9e98a8c4
No known key found for this signature in database
GPG key ID: 105BBD6D57F2B0C0

View file

@ -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;
}
}
`;
}
},