Skip to content

Commit a680543

Browse files
committed
build: optimize bundle size
use the light version of react-syntax-highlighter
1 parent 6b7404a commit a680543

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

components/annotated-source.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { useLayoutEffect, useMemo, useRef, useState } from 'react';
22
import ReactMarkdown from 'react-markdown/with-html';
3-
import SyntaxHighlighter from 'react-syntax-highlighter';
3+
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
4+
import arduino from 'react-syntax-highlighter/dist/cjs/languages/hljs/arduino';
5+
import clike from 'react-syntax-highlighter/dist/cjs/languages/hljs/c-like';
6+
import cpp from 'react-syntax-highlighter/dist/cjs/languages/hljs/cpp';
47
import { arduinoLight } from 'react-syntax-highlighter/dist/cjs/styles/hljs';
58
import { IGACAnnotation } from '../services/gac-annotations';
69

10+
SyntaxHighlighter.registerLanguage('c-like', clike); // `arduino` requires `clike`
11+
SyntaxHighlighter.registerLanguage('cpp', cpp); // `arduino` requires `cpp`
12+
SyntaxHighlighter.registerLanguage('arduino', arduino);
13+
714
interface IAnnotatedSourceProps {
815
code: string;
916
annotations: IGACAnnotation[];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Workaround for missing declaration in @types/react-syntax-highlighter
2+
3+
declare module 'react-syntax-highlighter/dist/cjs/languages/hljs/c-like' {
4+
const language: any;
5+
export default language;
6+
}

0 commit comments

Comments
 (0)