Allow highlight.js tree shaking; reduced production bundle size

This commit is contained in:
Willian Mitsuda 2021-10-20 19:23:10 -03:00
parent b21c10ab0b
commit 1bdae1569a
3 changed files with 16 additions and 12 deletions

View File

@ -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[];

View File

@ -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;

14
src/highlight-init.ts Normal file
View File

@ -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 };