Skip to content

Commit 728d623

Browse files
committed
perf(docs): lower bundle size by using shiki transformer
shiki by default uses inline styles for the codeblocks but we can convert it into common classes to lower its html output size hence lowering the bundle size too https://shiki.style/packages/transformers#transformerstyletoclass
1 parent 1f70702 commit 728d623

File tree

3 files changed

+198
-11
lines changed

3 files changed

+198
-11
lines changed

docs/.vitepress/config.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,32 @@ import { lucideIcons } from '../../vite/lucideIcons'
33
import path from 'path'
44
import { meta } from './meta'
55
import { getComponentItems } from './utils'
6-
6+
import { transformerStyleToClass } from '@shikijs/transformers'
77
import componentPreview from './plugins/componentPreview'
8+
import fs from 'fs'
9+
10+
// needed for transforming shiki inline styles to classes
11+
const toClass = transformerStyleToClass({
12+
classPrefix: 's_',
13+
})
814

915
export default defineConfig({
1016
srcDir: 'content',
1117
lastUpdated: true,
1218
title: meta.name,
1319
description: meta.description,
1420
titleTemplate: meta.name,
15-
1621
markdown: {
1722
theme: {
18-
dark: "tokyo-night",
19-
light: "github-light",
23+
dark: 'tokyo-night',
24+
light: 'github-light',
2025
},
26+
codeTransformers: [toClass],
2127
config(md) {
2228
md.use(componentPreview)
2329
},
2430
},
2531
cleanUrls: true,
26-
2732
head: [
2833
// newsreader font
2934
['link', { rel: 'preconnect', href: 'https://fonts.googleapis.com' }],
@@ -38,7 +43,6 @@ export default defineConfig({
3843
rel: 'stylesheet',
3944
},
4045
],
41-
4246
// set data-theme attribute since vitepress uses just the dark class.
4347
[
4448
'script',
@@ -50,7 +54,6 @@ export default defineConfig({
5054
localStorage.theme = theme
5155
})()`,
5256
],
53-
5457
// ===== Open Graph =====
5558
['meta', { property: 'og:type', content: 'website' }],
5659
['meta', { property: 'og:site_name', content: meta.name }],
@@ -67,7 +70,6 @@ export default defineConfig({
6770
['meta', { property: 'og:image:width', content: '1200' }],
6871
['meta', { property: 'og:image:height', content: '630' }],
6972
['meta', { property: 'og:image:alt', content: meta.description }],
70-
7173
// ===== Twitter =====
7274
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
7375
['meta', { name: 'twitter:title', content: meta.name }],
@@ -80,7 +82,6 @@ export default defineConfig({
8082
},
8183
],
8284
],
83-
8485
themeConfig: {
8586
componentList: getComponentItems(),
8687
outline: [2, 3],
@@ -95,15 +96,19 @@ export default defineConfig({
9596
{ icon: 'github', link: 'https://github.com/frappe/frappe-ui' },
9697
],
9798
},
98-
9999
vite: {
100100
plugins: [lucideIcons()],
101101
resolve: {
102102
alias: {
103103
'@/components': path.resolve(__dirname, '../components/'),
104104
'frappe-ui': path.resolve(__dirname, '../../src'),
105-
'dayjs/esm': 'dayjs'
105+
'dayjs/esm': 'dayjs',
106106
},
107107
},
108108
},
109+
buildEnd: async () => {
110+
const str = '/* Auto-generated on build-time */ \n\n ' + toClass.getCSS()
111+
const cssPath = path.resolve(__dirname, '../css/shiki.css')
112+
await fs.promises.writeFile(cssPath, str, 'utf-8')
113+
},
109114
})

docs/.vitepress/theme/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Theme } from 'vitepress'
22
import "../../../src/fonts/Inter/inter.css"
33
import "../../css/style.css"
4+
import "../../css/shiki.css"
45
import Demo from '../../components/Docs/Demo.vue'
56
import Layout from '../../components/Layout.vue'
67

docs/css/shiki.css

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/* Auto-generated on build-time */
2+
3+
.s_edvzsf {
4+
--shiki-dark: #7dcfff;
5+
--shiki-light: #d73a49;
6+
}
7+
.s_13ahmt {
8+
--shiki-dark: #9abdf5;
9+
--shiki-light: #24292e;
10+
}
11+
.s_4q1z3w {
12+
--shiki-dark: #0db9d7;
13+
--shiki-light: #24292e;
14+
}
15+
.s_w1p9wo {
16+
--shiki-dark: #89ddff;
17+
--shiki-light: #032f62;
18+
}
19+
.s_2575z4 {
20+
--shiki-dark: #9ece6a;
21+
--shiki-light: #032f62;
22+
}
23+
.s_50ecpt {
24+
--shiki-dark: #bb9af7;
25+
--shiki-light: #d73a49;
26+
}
27+
.s_euu481 {
28+
--shiki-dark: #c0caf5;
29+
--shiki-light: #6f42c1;
30+
}
31+
.s_1th9sy {
32+
--shiki-dark: #51597d;
33+
--shiki-dark-font-style: italic;
34+
--shiki-light: #6a737d;
35+
--shiki-light-font-style: inherit;
36+
}
37+
.s_bsv8nz {
38+
--shiki-dark: #73daca;
39+
--shiki-light: #e36209;
40+
}
41+
.s_2ekfrt {
42+
--shiki-dark: #89ddff;
43+
--shiki-light: #d73a49;
44+
}
45+
.s_i592pt {
46+
--shiki-dark: #0db9d7;
47+
--shiki-light: #005cc5;
48+
}
49+
.s_indoxt {
50+
--shiki-dark: #7aa2f7;
51+
--shiki-light: #6f42c1;
52+
}
53+
.s_fsg3al {
54+
--shiki-dark: #e0af68;
55+
--shiki-light: #e36209;
56+
}
57+
.s_2cy0ei {
58+
--shiki-dark: #a9b1d6;
59+
--shiki-light: #24292e;
60+
--shiki-dark-bg: #1a1b26;
61+
--shiki-light-bg: #fff;
62+
}
63+
.s_1zd9e2 {
64+
--shiki-dark: #ba3c97;
65+
--shiki-light: #24292e;
66+
}
67+
.s_1uuh8p {
68+
--shiki-dark: #f7768e;
69+
--shiki-light: #22863a;
70+
}
71+
.s_1i4ay4 {
72+
--shiki-dark: #bb9af7;
73+
--shiki-light: #6f42c1;
74+
}
75+
.s_1jjt6x {
76+
--shiki-dark: #89ddff;
77+
--shiki-light: #24292e;
78+
}
79+
.s_wac0bt {
80+
--shiki-dark: #de5971;
81+
--shiki-light: #22863a;
82+
}
83+
.s_r4oegk {
84+
--shiki-dark: #73daca;
85+
--shiki-light: #24292e;
86+
}
87+
.s_11933w {
88+
--shiki-dark: #7dcfff;
89+
--shiki-light: #24292e;
90+
}
91+
.s_22m8k2 {
92+
--shiki-dark: #c0caf5;
93+
--shiki-light: #24292e;
94+
}
95+
.s_6am9cx {
96+
--shiki-dark: #9aa5ce;
97+
--shiki-light: #24292e;
98+
}
99+
.s_252irl {
100+
--shiki-dark: #9d7cd8;
101+
--shiki-dark-font-style: italic;
102+
--shiki-light: #d73a49;
103+
--shiki-light-font-style: inherit;
104+
}
105+
.s_295sjd {
106+
--shiki-dark: #bb9af7;
107+
--shiki-light: #005cc5;
108+
}
109+
.s_40mev6 {
110+
--shiki-dark: #ff9e64;
111+
--shiki-light: #005cc5;
112+
}
113+
.s_29n2kq {
114+
--shiki-dark: #bb9af7;
115+
--shiki-dark-font-style: italic;
116+
--shiki-light: #d73a49;
117+
--shiki-light-font-style: inherit;
118+
}
119+
.s_20l85h {
120+
--shiki-dark: #7dcfff;
121+
--shiki-light: #032f62;
122+
}
123+
.s_28rvie {
124+
--shiki-dark: #ff5370;
125+
--shiki-dark-font-style: inherit;
126+
--shiki-light: #b31d28;
127+
--shiki-light-font-style: italic;
128+
}
129+
.s_y1rh3e {
130+
--shiki-dark: #646e9c;
131+
--shiki-dark-font-style: italic;
132+
--shiki-light: #d73a49;
133+
--shiki-light-font-style: inherit;
134+
}
135+
.s_21q2v7 {
136+
--shiki-dark: #89ddff;
137+
--shiki-dark-font-style: italic;
138+
--shiki-light: #032f62;
139+
--shiki-light-font-style: inherit;
140+
}
141+
.s_1cpno3 {
142+
--shiki-dark: #5a638c;
143+
--shiki-dark-font-style: italic;
144+
--shiki-light: #24292e;
145+
--shiki-light-font-style: inherit;
146+
}
147+
.s_12xt1b {
148+
--shiki-dark: #41a6b5;
149+
--shiki-light: #24292e;
150+
}
151+
.s_1vt12c {
152+
--shiki-dark: #7dcfff;
153+
--shiki-light: #005cc5;
154+
}
155+
.s_fjrnv8 {
156+
--shiki-dark: #f7768e;
157+
--shiki-dark-font-weight: bold;
158+
--shiki-light: #d73a49;
159+
--shiki-light-font-weight: inherit;
160+
}
161+
.s_2a1oer {
162+
--shiki-dark: #bb9af7;
163+
--shiki-light: #24292e;
164+
}
165+
.s_kq5psm {
166+
--shiki-dark: #a9b1d6;
167+
--shiki-light: #24292e;
168+
}
169+
.s_118ozv {
170+
--shiki-dark: #f7768e;
171+
--shiki-light: #005cc5;
172+
}
173+
.s_2d41qv {
174+
--shiki-dark: #e0af68;
175+
--shiki-light: #005cc5;
176+
}
177+
.s_g1fsda {
178+
--shiki-dark: #73daca;
179+
--shiki-light: #6f42c1;
180+
}
181+

0 commit comments

Comments
 (0)