Skip to content

Commit

Permalink
build: improve treeshaking
Browse files Browse the repository at this point in the history
  • Loading branch information
JB AUBREE committed Nov 27, 2024
1 parent d44ff31 commit 4b1ab0a
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 47 deletions.
2 changes: 1 addition & 1 deletion playground/src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const input = ref('')
const activeItem = ref()
const { primaryColor } = useAppTheme()
const toast = useToast()
const primaryOptions = computed(() => (Object.keys(colors) as (keyof typeof colors)[]).filter((color) => {
const primaryOptions = computed(() => (Object.keys(colors) as (keyof typeof colors)[]).map(color => color.toString()).filter((color) => {
return !['inherit', 'current', 'black', 'white', 'light', 'dark', 'transparent', 'primary', 'pilot', 'success', 'danger'].includes(color)
}))
const dropdownItems = [
Expand Down
2 changes: 1 addition & 1 deletion playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"jsx": "preserve",
"skipLibCheck": true,
"isolatedModules": true,
"moduleResolution": "node",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"strictNullChecks": true,
"allowJs": true,
Expand Down
43 changes: 0 additions & 43 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,6 @@ import { APP_UI } from './symbols'
import type { DeepPartial, PluginOptions, ResolvedPluginOptions } from './types'
import { colors } from '~/preset'

const components = {
UAvatar,
UButton,
UBreadcrumb,
UCard,
UCheckbox,
UCollapse,
UContainer,
UDatepicker,
UDialog,
UDropdown,
UFileUpload,
UFormGroup,
UIcon,
UInput,
ULinkCustom,
UNav,
UNotification,
UNotifications,
UPopover,
UPagination,
URadio,
URadioGroup,
USelect,
USelectMenu,
USkeleton,
USlider,
UTable,
UTag,
UText,
UTextarea,
UToggle,
UTooltip,
UVerticalNavigation,
}

declare module 'vue' {
export interface GlobalComponents {
UAvatar: typeof UAvatar
Expand Down Expand Up @@ -121,7 +85,6 @@ declare module 'vue' {
}

const configDefaults: ResolvedPluginOptions = {
registerComponents: true,
appConfig,
}

Expand All @@ -133,12 +96,6 @@ const plugin = {

app.use(createHead())

if (options.registerComponents) {
Object.entries(components).forEach(([name, component]) => {
app.component(name, component)
})
}

const hexToRgb = (hex: string) => {
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i
Expand Down
2 changes: 0 additions & 2 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import type { Colors } from '~/preset'
import type { DeepPartial } from '~/types'

export interface PluginOptions {
registerComponents: boolean
appConfig: DeepPartial<typeof appConfig>
}

export interface ResolvedPluginOptions {
registerComponents: boolean
appConfig: typeof appConfig
}

Expand Down
4 changes: 4 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const config = defineConfig({
file.code = file.code.replace(/},\s*h\s*=\s*{/g, '}, hh = {')
file.code = file.code.replace(/:\s*h\s*,/g, ': hh,')
}
if (file.type === 'chunk' && file.code && fileName === 'index.js') {
file.code = file.code.replace(/, h\s=\s/g, ', hh = ')
file.code = file.code.replace(/\.{3}h/g, '...hh')
}
}
},
},
Expand Down

0 comments on commit 4b1ab0a

Please # to comment.