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:
parent
c97ebaa41e
commit
81c014173c
1 changed files with 5 additions and 1 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue