Skip to content

Commit

Permalink
refactor(console): load mermaid in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gao-sun committed Jul 1, 2024
1 parent 362ddc6 commit f39f60d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/console/src/mdx-components/Mermaid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit f39f60d

Please sign in to comment.