From d43202f1372f8102af96fb08d29faff1fce1cc7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Thu, 24 Oct 2024 10:16:56 +0200 Subject: [PATCH] Reduce bundle size of shiki (#2551) --- .changeset/lovely-hounds-invent.md | 5 ++++ bun.lockb | Bin 580040 -> 580040 bytes packages/gitbook/package.json | 2 +- .../DocumentView/CodeBlock/highlight.ts | 22 +++++++++++------- 4 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 .changeset/lovely-hounds-invent.md diff --git a/.changeset/lovely-hounds-invent.md b/.changeset/lovely-hounds-invent.md new file mode 100644 index 000000000..f789f98c7 --- /dev/null +++ b/.changeset/lovely-hounds-invent.md @@ -0,0 +1,5 @@ +--- +'gitbook': patch +--- + +Optimize bundle size of the server output by reducing bundle size of shiki (skipping themes) diff --git a/bun.lockb b/bun.lockb index ef86153b2d70e97d5d52391c10441fec6b2b2208..2301ce2b429a4a4669ef06f66beef72a3385b87f 100755 GIT binary patch delta 40 ucmX@HS^30f<%Sl<7N!>F7M2#)Eo{=PEJj9p2JP~!Y(UJuU7nR=F7M2#)Eo{=PEQW@9hVAmKY(UJuU7nR=({ + langs: bundledLanguages, + themes: {}, + engine: () => createOnigurumaEngine(import('shiki/wasm')), +}); + /** * Load the highlighter, only once, and reuse it. * It makes sure to handle concurrent calls. @@ -312,7 +315,8 @@ const loadHighlighter = singleton(async () => { // Otherwise for Vercel/Cloudflare, we need to load it ourselves. await loadWasm((obj) => WebAssembly.instantiate(onigWasm, obj)); } - const highlighter = await getHighlighter({ + + const highlighter = await createHighlighter({ themes: [createCssVariablesTheme()], langs: [], }); @@ -322,7 +326,7 @@ const loadHighlighter = singleton(async () => { const loadLanguagesMutex = asyncMutexFunction(); async function loadHighlighterLanguage( - highlighter: HighlighterGeneric, + highlighter: HighlighterGeneric, lang: keyof typeof bundledLanguages, ) { await loadLanguagesMutex.runBlocking(async () => {