Skip to content

Commit

Permalink
feat: fix dynamic require
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjosephprice committed May 17, 2024
1 parent 46c0acd commit 2482231
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions components/Code/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import React, { createRef } from 'react';
// https://github.com/codemirror/CodeMirror/issues/3701#issuecomment-164904534
let syntaxHighlighter;
let canonicalLanguage = _ => '';

if (typeof window !== 'undefined') {
// eslint-disable-next-line global-require
syntaxHighlighter = require('@readme/syntax-highlighter').default;
// eslint-disable-next-line global-require
({ canonical: canonicalLanguage } = require('@readme/syntax-highlighter'));
const module = await import('@readme/syntax-highlighter');

syntaxHighlighter = module.default;
canonicalLanguage = module.canonical;
}

console.log(syntaxHighlighter);

function CopyCode({ codeRef, rootClass = 'rdmd-code-copy', className = '' }) {
const copyClass = `${rootClass}_copied`;
const button = createRef<HTMLButtonElement>();
Expand Down
2 changes: 1 addition & 1 deletion example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HashRouter, Navigate, Route, Routes } from 'react-router-dom';

import GlossaryContext from '../contexts/GlossaryTerms';

require('./demo.scss');
import './demo.scss';

import Root from './Root';
import docs from './docs';
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"DOM", // Loaded to our global type availability for access to `fetch`.
"DOM.iterable"
],
"module": "es2020",
"module": "es2022",
"moduleResolution": "Bundler",
"outDir": "dist",
"sourceMap": true,
"target": "ES2015",
"target": "ES2017",
"types": ["vitest/globals"]
},
"include": ["./index.ts", "./options.js", "./components", "./contexts", "./example", "./lib", "./processor"],
Expand Down

0 comments on commit 2482231

Please sign in to comment.