Skip to content

Commit

Permalink
perf: optimise SyntaxHighlighter
Browse files Browse the repository at this point in the history
reduces bundle size by 76% (from 1MB to 260KB)
  • Loading branch information
Beraliv committed Dec 27, 2024
1 parent 442b902 commit e1de0b1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/CodeExample.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SyntaxHighlighter from "react-syntax-highlighter";
import { Light as SyntaxHighlighter } from "react-syntax-highlighter";
import typescriptLanguage from "react-syntax-highlighter/dist/esm/languages/hljs/typescript";
import {
tomorrow,
tomorrowNightEighties,
Expand All @@ -13,6 +14,12 @@ import { UserInputContext } from "../contexts/UserInputContext";

import style from "./CodeExample.module.css";

// This project only requires TypeScript language support, therefore avoid
// importing default SyntaxHighlighter to minimise the bundle size impact. With
// default import, the bundle size increased by ~840 KB.

SyntaxHighlighter.registerLanguage("typescript", typescriptLanguage);

export const CodeExample = () => {
const { source, target } = useContext(UserInputContext);
const theme = useTheme();
Expand Down

0 comments on commit e1de0b1

Please sign in to comment.