Skip to content

Commit 7c5bf71

Browse files
use improved shiki node version now that we're on static
1 parent ba0f911 commit 7c5bf71

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

apps/website/src/components/highlight/highlight.tsx

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
import { ClassList, PropsOf, component$, useSignal, useTask$ } from '@builder.io/qwik';
1+
import { ClassList, PropsOf, component$, useSignal, useTask$, $ } from '@builder.io/qwik';
22
import { CodeCopy } from '../code-copy/code-copy';
33
import { cn } from '@qwik-ui/utils';
4-
import poimandres from 'shiki/themes/poimandres.mjs';
5-
import html from 'shiki/langs/html.mjs';
6-
import css from 'shiki/langs/css.mjs';
7-
import tsx from 'shiki/langs/tsx.mjs';
8-
import { createHighlighterCore, BundledLanguage } from 'shiki/index.mjs';
9-
10-
// Create a single highlighter instance
11-
const highlighterPromise = createHighlighterCore({
12-
themes: [poimandres],
13-
langs: [html, css, tsx],
14-
loadWasm: import('shiki/wasm'),
15-
});
4+
import { codeToHtml } from 'shiki';
165

176
export type HighlightProps = PropsOf<'div'> & {
187
code: string;
198
copyCodeClass?: ClassList;
20-
language?: BundledLanguage;
9+
language?: 'tsx' | 'html' | 'css';
2110
splitCommentStart?: string;
2211
splitCommentEnd?: string;
2312
};
@@ -33,26 +22,31 @@ export const Highlight = component$(
3322
}: HighlightProps) => {
3423
const codeSig = useSignal('');
3524

36-
useTask$(async ({ track }) => {
37-
track(() => code);
25+
const addShiki$ = $(async () => {
3826
let modifiedCode: string = code;
3927

4028
let partsOfCode = modifiedCode.split(splitCommentStart);
29+
4130
if (partsOfCode.length > 1) {
4231
modifiedCode = partsOfCode[1];
4332
}
4433

4534
partsOfCode = modifiedCode.split(splitCommentEnd);
35+
4636
if (partsOfCode.length > 1) {
4737
modifiedCode = partsOfCode[0];
4838
}
4939

50-
const highlighter = await highlighterPromise;
51-
const str = highlighter.codeToHtml(modifiedCode, {
40+
const str = await codeToHtml(modifiedCode, {
5241
lang: language,
5342
theme: 'poimandres',
5443
});
55-
codeSig.value = str;
44+
45+
codeSig.value = str.toString();
46+
});
47+
48+
useTask$(async () => {
49+
await addShiki$();
5650
});
5751

5852
return (

apps/website/vite.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,10 @@ export default defineConfig(async () => {
105105
'Cache-Control': 'public, max-age=600',
106106
},
107107
},
108+
optimizeDeps: {
109+
// Put problematic deps that break bundling here, mostly those with binaries.
110+
// For example ['better-sqlite3'] if you use that in server functions.
111+
exclude: ['shiki'],
112+
},
108113
};
109114
});

0 commit comments

Comments
 (0)