From 1bdae1569a2a0a0e6c809bf013b612fd246eedba Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 20 Oct 2021 19:23:10 -0300 Subject: [PATCH] Allow highlight.js tree shaking; reduced production bundle size --- src/address/ABI.tsx | 7 +------ src/address/Contract.tsx | 7 +------ src/highlight-init.ts | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 src/highlight-init.ts diff --git a/src/address/ABI.tsx b/src/address/ABI.tsx index 7190f4e..a714367 100644 --- a/src/address/ABI.tsx +++ b/src/address/ABI.tsx @@ -1,10 +1,5 @@ import React from "react"; -import { Light as SyntaxHighlighter } from "react-syntax-highlighter"; -import hljs from "highlight.js"; -import docco from "react-syntax-highlighter/dist/esm/styles/hljs/docco"; - -import hljsDefineSolidity from "highlightjs-solidity"; -hljsDefineSolidity(hljs); +import { SyntaxHighlighter, docco } from "../highlight-init"; type ABIProps = { abi: any[]; diff --git a/src/address/Contract.tsx b/src/address/Contract.tsx index 7ddfe56..5432f51 100644 --- a/src/address/Contract.tsx +++ b/src/address/Contract.tsx @@ -1,12 +1,7 @@ import React from "react"; -import { Light as SyntaxHighlighter } from "react-syntax-highlighter"; -import hljs from "highlight.js"; -import docco from "react-syntax-highlighter/dist/esm/styles/hljs/docco"; +import { SyntaxHighlighter, docco } from "../highlight-init"; import { useContract } from "../useSourcify"; - -import hljsDefineSolidity from "highlightjs-solidity"; import { useAppConfigContext } from "../useAppConfig"; -hljsDefineSolidity(hljs); type ContractProps = { checksummedAddress: string; diff --git a/src/highlight-init.ts b/src/highlight-init.ts new file mode 100644 index 0000000..f8318eb --- /dev/null +++ b/src/highlight-init.ts @@ -0,0 +1,14 @@ +import { Light as SyntaxHighlighter } from "react-syntax-highlighter"; + +// @ts-ignore +import hljs from "highlight.js/lib/core"; + +// @ts-ignore +import json from "highlight.js/lib/languages/json"; +import docco from "react-syntax-highlighter/dist/esm/styles/hljs/docco"; + +import hljsDefineSolidity from "highlightjs-solidity"; +hljsDefineSolidity(hljs); +hljs.registerLanguage("json", json); + +export { SyntaxHighlighter, docco };