Skip to content

Commit

Permalink
perf(desktop): reduce bundle size by ~8.5MB from shiki (#97)
Browse files Browse the repository at this point in the history
* perf(desktop): reduce bundle size by ~8.5MB from shiki

Use fine grained shiki bundle

* ci: update GitHub Actions workflow build step description
  • Loading branch information
HuakunShen authored Feb 7, 2025
1 parent 0eacf01 commit 5573923
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/beta-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ jobs:
- name: Build Packages
run: pnpm build

- name: Build the app (Windows)
- name: Build the App
working-directory: apps/desktop
env:
CI: false
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
},
"dependencies": {
"@formkit/auto-animate": "^0.8.2",
"@shikijs/langs": "^2.3.2",
"@shikijs/themes": "^2.3.2",
"@inlang/paraglide-sveltekit": "^0.15.5",
"@internationalized/date": "^3.7.0",
"@kksh/supabase": "workspace:*",
Expand Down
18 changes: 12 additions & 6 deletions packages/ui/src/components/code/shiki.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<!-- https://shiki.style/guide/bundles#fine-grained-bundle -->
<script lang="ts">
import { cn } from "@kksh/ui/utils"
import { getSingletonHighlighter } from "shiki"
import { ShikiMagicMove } from "shiki-magic-move/svelte"
import "shiki-magic-move/dist/style.css"
import { createHighlighterCore } from "shiki/core"
import { createOnigurumaEngine } from "shiki/engine/oniguruma"
const {
code,
Expand All @@ -20,12 +21,17 @@
class?: string
} = $props()
const highlighter2 = getSingletonHighlighter({
themes: ["vitesse-dark", "vitesse-light"],
langs: ["typescript", "bash", "powershell", "json"]
const highlighter2 = createHighlighterCore({
themes: [import("@shikijs/themes/vitesse-dark"), import("@shikijs/themes/vitesse-light")],
langs: [
import("@shikijs/langs/json"),
import("@shikijs/langs/typescript"),
import("@shikijs/langs/bash"),
import("@shikijs/langs/powershell")
],
// `shiki/wasm` contains the wasm binary inlined as base64 string.
engine: createOnigurumaEngine(import("shiki/wasm"))
})
let code2 = $state(`const hello = 'world'`)
</script>

{#await highlighter2 then highlighter}
Expand Down
30 changes: 29 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5573923

Please sign in to comment.