Skip to content

Commit beff417

Browse files
committed
fix: avoid building all the shiki lang files.
1 parent 738bbc6 commit beff417

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

resources/js/shiki.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
1-
import { getHighlighter } from 'shiki';
1+
import { getHighlighterCore } from 'shiki/core'
2+
import getWasm from 'shiki/wasm'
23
import { ref } from 'vue'
34

45
export const highlighter = () => {
5-
const theme = 'github-dark';
66
const loaded = ref(false);
77
const loading = ref(false);
88
let highlighter;
99

10-
1110
const install = async () => {
1211
if (highlighter || loading.value) {
1312
return;
1413
}
1514

1615
loading.value = true;
1716

18-
const langs = ['html', 'php', 'js', 'json', 'vue', 'sh', 'blade'];
19-
highlighter = await getHighlighter({ themes: [theme], langs });
17+
highlighter = await getHighlighterCore({
18+
themes: [
19+
() => import('shiki/dist/themes/github-dark.mjs'),
20+
],
21+
langs: [
22+
() => import('shiki/dist/langs/html.mjs'),
23+
() => import('shiki/dist/langs/php.mjs'),
24+
() => import('shiki/dist/langs/javascript.mjs'),
25+
() => import('shiki/dist/langs/json.mjs'),
26+
() => import('shiki/dist/langs/vue.mjs'),
27+
() => import('shiki/dist/langs/shellscript.mjs'),
28+
() => import('shiki/dist/langs/blade.mjs'),
29+
],
30+
loadWasm: getWasm,
31+
});
2032

2133
loaded.value = true;
2234
loading.value = false;
@@ -32,7 +44,10 @@ export const highlighter = () => {
3244
}]));
3345
}
3446

35-
return highlighter.codeToTokensBase(text, { lang, theme });
47+
return highlighter.codeToTokensBase(text, {
48+
lang,
49+
theme: 'github-dark',
50+
});
3651
}
3752

3853
return { install, getLines, loaded }

0 commit comments

Comments
 (0)