Skip to content

Commit

Permalink
fix: avoid building all the shiki lang files.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiCO2k committed Feb 19, 2024
1 parent 738bbc6 commit beff417
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions resources/js/shiki.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
import { getHighlighter } from 'shiki';
import { getHighlighterCore } from 'shiki/core'
import getWasm from 'shiki/wasm'
import { ref } from 'vue'

export const highlighter = () => {
const theme = 'github-dark';
const loaded = ref(false);
const loading = ref(false);
let highlighter;


const install = async () => {
if (highlighter || loading.value) {
return;
}

loading.value = true;

const langs = ['html', 'php', 'js', 'json', 'vue', 'sh', 'blade'];
highlighter = await getHighlighter({ themes: [theme], langs });
highlighter = await getHighlighterCore({
themes: [
() => import('shiki/dist/themes/github-dark.mjs'),
],
langs: [
() => import('shiki/dist/langs/html.mjs'),
() => import('shiki/dist/langs/php.mjs'),
() => import('shiki/dist/langs/javascript.mjs'),
() => import('shiki/dist/langs/json.mjs'),
() => import('shiki/dist/langs/vue.mjs'),
() => import('shiki/dist/langs/shellscript.mjs'),
() => import('shiki/dist/langs/blade.mjs'),
],
loadWasm: getWasm,
});

loaded.value = true;
loading.value = false;
Expand All @@ -32,7 +44,10 @@ export const highlighter = () => {
}]));
}

return highlighter.codeToTokensBase(text, { lang, theme });
return highlighter.codeToTokensBase(text, {
lang,
theme: 'github-dark',
});
}

return { install, getLines, loaded }
Expand Down

0 comments on commit beff417

Please sign in to comment.