Skip to content

Commit

Permalink
feat: improve treeshaking
Browse files Browse the repository at this point in the history
  • Loading branch information
JB AUBREE committed Oct 30, 2024
1 parent 819c557 commit 83046a3
Show file tree
Hide file tree
Showing 35 changed files with 85 additions and 25 deletions.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
"sideEffects": false,
"exports": {
".": {
"import": "./dist/unuse-ui.js",
"require": "./dist/unuse-ui.umd.cjs"
"import": "./dist/index.js"
},
"./dist/style.css": "./dist/style.css"
"./dist/style.css": "./dist/assets/style.css"
},
"main": "./dist/unuse-ui.umd.cjs",
"module": "./dist/unuse-ui.js",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/unuse-ui.d.ts",
"files": [
"dist"
Expand Down
1 change: 0 additions & 1 deletion playground/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ declare module 'vue' {
export interface GlobalComponents {
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
UAvatar: typeof import('unuse-ui')['UAvatar']
UBreadcrumb: typeof import('unuse-ui')['UBreadcrumb']
UButton: typeof import('unuse-ui')['UButton']
UCard: typeof import('unuse-ui')['UCard']
Expand Down
2 changes: 1 addition & 1 deletion playground/uno.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineConfig({
],
content: {
pipeline: {
include: [/.*\/unuse-ui\.js(.*)?$/, './**/*.vue'],
include: [/.*\/unuse-ui\/.*[^/]+\.js$/, './**/*.vue'],
},
},
})
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

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

2 changes: 2 additions & 0 deletions src/components/avatar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as UAvatar } from './UAvatar.vue'
export type { Avatar } from './avatar'
1 change: 1 addition & 0 deletions src/components/breadcrumb/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UBreadcrumb } from './UBreadcrumb.vue'
2 changes: 2 additions & 0 deletions src/components/button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as UButton } from './UButton.vue'
export type { Button, ButtonColor, ButtonVariant } from './button'
1 change: 1 addition & 0 deletions src/components/card/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UCard } from './UCard.vue'
1 change: 1 addition & 0 deletions src/components/checkbox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UCheckbox } from './UCheckbox.vue'
1 change: 1 addition & 0 deletions src/components/collapse/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UCollapse } from './UCollapse.vue'
1 change: 1 addition & 0 deletions src/components/container/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UContainer } from './UContainer.vue'
2 changes: 2 additions & 0 deletions src/components/datepicker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as UDatepicker } from './UDatepicker.vue'
export type { DateType } from './datepicker'
1 change: 1 addition & 0 deletions src/components/dialog/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UDialog } from './UDialog.vue'
2 changes: 2 additions & 0 deletions src/components/dropdown/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as UDropdown } from './UDropdown.vue'
export type { DropdownItem } from './dropdown'
1 change: 1 addition & 0 deletions src/components/file-upload/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UFileUpload } from './UFileUpload.vue'
1 change: 1 addition & 0 deletions src/components/form-group/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UFormGroup } from './UFormGroup.vue'
1 change: 1 addition & 0 deletions src/components/icon/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UIcon } from './UIcon.vue'
2 changes: 2 additions & 0 deletions src/components/input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as UInput } from './UInput.vue'
export type { Input, InputColor, InputVariant } from './input'
1 change: 1 addition & 0 deletions src/components/link/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as ULinkCustom } from './ULinkCustom.vue'
1 change: 1 addition & 0 deletions src/components/nav/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UNav } from './UNav.vue'
2 changes: 2 additions & 0 deletions src/components/notification/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as UNotifications } from './UNotifications.vue'
export type { Notification, NotificationAction } from './notification'
1 change: 1 addition & 0 deletions src/components/pagination/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UPagination } from './UPagination.vue'
1 change: 1 addition & 0 deletions src/components/popover/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UPopover } from './UPopover.vue'
2 changes: 2 additions & 0 deletions src/components/radio/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as URadio } from './URadio.vue'
export { default as URadioGroup } from './URadioGroup.vue'
2 changes: 2 additions & 0 deletions src/components/select/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as USelect } from './USelect.vue'
export { default as USelectMenu } from './USelectMenu.vue'
1 change: 1 addition & 0 deletions src/components/skeleton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as USkeleton } from './USkeleton.vue'
1 change: 1 addition & 0 deletions src/components/slider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as USlider } from './USlider.vue'
1 change: 1 addition & 0 deletions src/components/table/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UTable } from './UTable.vue'
2 changes: 2 additions & 0 deletions src/components/tag/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as UTag } from './UTag.vue'
export type { TagVariant } from './tag'
1 change: 1 addition & 0 deletions src/components/text/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UText } from './UText.vue'
1 change: 1 addition & 0 deletions src/components/textarea/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UTextarea } from './UTextarea.vue'
1 change: 1 addition & 0 deletions src/components/toggle/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UToggle } from './UToggle.vue'
1 change: 1 addition & 0 deletions src/components/tooltip/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UTooltip } from './UTooltip.vue'
1 change: 1 addition & 0 deletions src/components/vertical-navigation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as UVerticalNavigation } from './UVerticalNavigation.vue'
39 changes: 31 additions & 8 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { resolve } from 'node:path'
import path, { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import dts from 'vite-plugin-dts'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { glob } from 'glob'

const entry = Object.fromEntries(
glob
.sync('src/components/*/index.ts')
.map(file => [
path.relative('src', file.slice(0, file.length - path.extname(file).length)),
fileURLToPath(new URL(file, import.meta.url)),
]),
)

const config = defineConfig({
resolve: {
Expand All @@ -30,23 +41,35 @@ const config = defineConfig({
Components({
dts: 'src/components.d.ts',
}),
{
name: 'post-process-rename-h',
enforce: 'post',
generateBundle(_options, bundle) {
for (const [fileName, file] of Object.entries(bundle)) {
if (file.type === 'chunk' && file.code && fileName.match(/^index-.*\.js$/)) {
file.code = file.code.replace(/},\s*h\s*=\s*{/g, '}, hh = {')
file.code = file.code.replace(/:\s*h\s*,/g, ': hh,')
}
}
},
},
],
build: {
emptyOutDir: false,
lib: {
entry: resolve(__dirname, 'src/unuse-ui.ts'),
name: 'unuse-ui',
fileName: 'unuse-ui',
entry: {
...entry,
index: fileURLToPath(new URL('src/unuse-ui.ts', import.meta.url)),
},
formats: ['es'],
},
rollupOptions: {
external: [
'vue',
],
output: {
exports: 'named',
globals: {
vue: 'Vue',
},
assetFileNames: 'assets/[name][extname]',
entryFileNames: '[name].js',
},
},
},
Expand Down

0 comments on commit 83046a3

Please # to comment.