Skip to content

Commit c6ffaed

Browse files
build(applet+client): reduce bundle size (#527)
1 parent 555671f commit c6ffaed

File tree

14 files changed

+77
-150
lines changed

14 files changed

+77
-150
lines changed

packages/applet/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'uno.css'
22
import '@unocss/reset/tailwind.css'
33
import './styles/base.css'
4-
import 'floating-vue/dist/style.css'
4+
import '@vue/devtools-ui/style.css'
55

66
export * from './modules/pinia'
77
export * from './modules/components'

packages/applet/src/modules/components/components/RenderCode.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import CodeBlock from '~/components/basic/CodeBlock.vue'
2+
import { VueCodeBlock } from '@vue/devtools-ui'
33
44
defineProps<{
55
code: string
@@ -19,7 +19,7 @@ function close() {
1919
<i class="i-carbon-close cursor-pointer hover:op80" @click="close" />
2020
</div>
2121
<div class="flex-1 overflow-scroll text-3.5">
22-
<CodeBlock :code="code" lang="javascript" />
22+
<VueCodeBlock :code="code" lang="javascript" />
2323
</div>
2424
</div>
2525
</template>

packages/applet/vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { resolve } from 'node:path'
22
import Vue from '@vitejs/plugin-vue'
33
import Unocss from 'unocss/vite'
44
import Dts from 'vite-plugin-dts'
5+
import { dependencies, peerDependencies } from './package.json'
56

67
const argv = process.argv.slice(2)
78
const enableWatch = argv.includes('--watch')
@@ -26,7 +27,7 @@ export default {
2627
formats: ['es', 'cjs'],
2728
},
2829
rollupOptions: {
29-
external: ['vue'],
30+
external: [...Object.keys(peerDependencies), ...Object.keys(dependencies)],
3031
output: {
3132
assetFileNames: 'index.[ext]',
3233
globals: {

packages/client/src/components/code/CodeBlock.vue

Lines changed: 0 additions & 63 deletions
This file was deleted.

packages/client/src/components/code/CodeSnippets.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import type { BuiltinLanguage } from 'shiki'
33
import type { CodeSnippet } from '@vue/devtools-core'
4-
import { VueButton } from '@vue/devtools-ui'
4+
import { VueButton, VueCodeBlock } from '@vue/devtools-ui'
55
66
const props = defineProps<{
77
codeSnippets: CodeSnippet[]
@@ -38,7 +38,7 @@ watchEffect(() => {
3838
</div>
3939

4040
<template v-if="selected">
41-
<CodeBlock
41+
<VueCodeBlock
4242
:code="selected.code"
4343
:lang="selectedLang"
4444
:lines="false"

packages/client/src/composables/shiki.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

packages/client/src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import '@unocss/reset/tailwind.css'
2-
import 'floating-vue/dist/style.css'
3-
import { getViteClient } from 'vite-hot-client'
2+
import 'uno.css'
3+
import '@vue/devtools-ui/style.css'
44

5+
import { getViteClient } from 'vite-hot-client'
56
import { isInChromePanel, isInSeparateWindow } from '@vue/devtools-shared'
67
import { VueDevToolsVuePlugin, createViteClientRpc, functions, rpc } from '@vue/devtools-core'
78
import { createRpcClient, setViteClientContext } from '@vue/devtools-kit'
@@ -22,7 +23,6 @@ import CustomTabView from '~/pages/custom-tab-view.vue'
2223
import CustomInspectorTabView from '~/pages/custom-inspector-tab-view.vue'
2324
import WaitForConnection from '~/components/WaitForConnection.vue'
2425

25-
import 'uno.css'
2626
import '~/assets/styles/main.css'
2727

2828
const routes = [

packages/ui/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"require": "./dist/index.cjs"
1212
},
1313
"./style.css": "./dist/style.css",
14+
"./uno.css": "./dist/uno.css",
1415
"./theme": {
1516
"types": "./dist/types/theme/index.d.ts",
1617
"import": "./dist/theme.js",
@@ -32,6 +33,7 @@
3233
"peerDependencies": {
3334
"@unocss/reset": ">=0.50.0-0",
3435
"floating-vue": ">=2.0.0-0",
36+
"shiki": ">=1.10.0",
3537
"unocss": ">=0.50.0-0",
3638
"vue": ">=3.0.0-0"
3739
},

packages/applet/src/components/basic/CodeBlock.vue renamed to packages/ui/src/components/CodeBlock.vue

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
// This components requires to run in DevTools to render correctly
33
import { computed, nextTick } from 'vue'
44
import type { BuiltinLanguage } from 'shiki'
5-
import { renderCodeHighlight } from '~/composables/shiki'
5+
import { renderCodeHighlight } from '../composables/shiki'
6+
7+
export interface VueCodeBlockProps {
8+
code: string
9+
lang?: BuiltinLanguage | 'text'
10+
lines?: boolean
11+
transformRendered?: (code: string) => string
12+
}
613
714
const props = withDefaults(
8-
defineProps<{
9-
code: string
10-
lang?: BuiltinLanguage | 'text'
11-
lines?: boolean
12-
transformRendered?: (code: string) => string
13-
}>(),
15+
defineProps<VueCodeBlockProps>(),
1416
{
1517
lines: true,
1618
},
@@ -46,22 +48,31 @@ const rendered = computed(() => {
4648
</template>
4749
</template>
4850

49-
<style>
50-
.code-block-lines .shiki code {
51-
counter-reset: step;
52-
counter-increment: step calc(var(--start, 1) - 1);
53-
}
54-
.code-block-lines .shiki code .line::before {
55-
content: counter(step);
56-
counter-increment: step;
57-
width: 2.5rem;
58-
padding-right: 0.5rem;
59-
margin-right: 0.5rem;
60-
display: inline-block;
61-
text-align: right;
62-
--at-apply: 'text-truegray:50';
63-
}
64-
.code-block pre:focus-visible {
65-
outline: none;
51+
<style lang="postcss">
52+
.code-block-lines {
53+
.shiki {
54+
code {
55+
counter-reset: step;
56+
counter-increment: step calc(var(--start, 1) - 1);
57+
58+
.line {
59+
&::before {
60+
content: counter(step);
61+
counter-increment: step;
62+
width: 2.5rem;
63+
padding-right: 0.5rem;
64+
margin-right: 0.5rem;
65+
display: inline-block;
66+
text-align: right;
67+
--at-apply: 'text-truegray:50';
68+
}
69+
}
70+
}
71+
}
72+
pre {
73+
&:focus-visible {
74+
outline: none;
75+
}
76+
}
6677
}
6778
</style>

packages/ui/src/components/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Overlay from './Overlay.vue'
1818
import Notification from './Notification.vue'
1919
import Tooltip from './Tooltip.vue'
2020
import IcIcon from './IcIcon.vue'
21+
import CodeBlock from './CodeBlock.vue'
2122

2223
export {
2324
Badge as VueBadge,
@@ -40,6 +41,7 @@ export {
4041
Notification as VueNotification,
4142
Tooltip as VueTooltip,
4243
IcIcon as VueIcIcon,
44+
CodeBlock as VueCodeBlock,
4345
}
4446

4547
export type * from './Button.vue'
@@ -61,3 +63,5 @@ export type * from './Drawer.vue'
6163
export type * from './Overlay.vue'
6264
export type * from './Notification.vue'
6365
export type * from './Tooltip.vue'
66+
export type * from './IcIcon.vue'
67+
export type * from './CodeBlock.vue'

0 commit comments

Comments
 (0)