0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

refactor(console): load mermaid in dev (#6155)

This commit is contained in:
Gao Sun 2024-07-02 10:38:43 +08:00 committed by GitHub
parent c97ebaa41e
commit 81c014173c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,12 +4,16 @@ import { useEffect } from 'react';
import useTheme from '@/hooks/use-theme';
/** Load Mermaid asynchronously from jsDelivr to avoid Parcel issues. */
const loadMermaid = async () => {
// Define this variable to "outsmart" the detection of the dynamic import by Parcel:
// https://github.com/parcel-bundler/parcel/issues/7064#issuecomment-942441649
const uri = 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const imported: { default: MermaidType } = await import(uri);
const imported: { default: MermaidType } = await (process.env.NODE_ENV === 'development'
? // eslint-disable-next-line no-eval -- https://github.com/parcel-bundler/parcel/issues/8316
eval(`import('${uri}')`)
: import(uri));
return imported.default;
};