diff --git a/package.json b/package.json index b95c214804..c4d1310169 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "build:css": "vite build --config vite.config.css.ts", "build:lib": "vite build --config vite.config.lib.ts", "build:umd": "vite build --config vite.config.umd.ts", + "build:demo": "vite build --config vite.config.demo.ts", "build:docs": "pnpm run -C docs build", "serve:docs": "pnpm run -C docs serve", "build:start": "pnpm run -C start build", @@ -35,7 +36,6 @@ "@commitlint/config-conventional": "^17.0.0", "@fighting-design/fighting-components": "workspace:*", "@fighting-design/fighting-theme": "workspace:*", - "@fighting-design/fighting-utils": "workspace:*", "@vitejs/plugin-vue": "^2.3.1", "@vue/runtime-core": "^3.2.37", "@vue/test-utils": "^2.0.0-rc.18", @@ -78,4 +78,4 @@ "git add" ] } -} +} \ No newline at end of file diff --git a/packages/fighting-components/README.md b/packages/fighting-components/README.md index 5f773cf01c..a987ac8dc7 100644 --- a/packages/fighting-components/README.md +++ b/packages/fighting-components/README.md @@ -177,7 +177,7 @@ const fun: a = (a: number, b: number): number => { ```ts import FButton from './src/button.vue' -import { install } from '@fighting-design/fighting-utils' +import { install } from '../_utils' install(FButton, FButton.name) diff --git a/packages/fighting-utils/type/button.d.ts b/packages/fighting-components/_interface/button.d.ts similarity index 100% rename from packages/fighting-utils/type/button.d.ts rename to packages/fighting-components/_interface/button.d.ts diff --git a/packages/fighting-utils/type/change-color.d.ts b/packages/fighting-components/_interface/change-color.d.ts similarity index 100% rename from packages/fighting-utils/type/change-color.d.ts rename to packages/fighting-components/_interface/change-color.d.ts diff --git a/packages/fighting-components/_interface/env.d.ts b/packages/fighting-components/_interface/env.d.ts new file mode 100644 index 0000000000..aafef9509d --- /dev/null +++ b/packages/fighting-components/_interface/env.d.ts @@ -0,0 +1,8 @@ +/// + +declare module '*.vue' { + import type { DefineComponent } from 'vue' + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types + const component: DefineComponent<{}, {}, any> + export default component +} diff --git a/packages/fighting-utils/type/image.d.ts b/packages/fighting-components/_interface/image.d.ts similarity index 100% rename from packages/fighting-utils/type/image.d.ts rename to packages/fighting-components/_interface/image.d.ts diff --git a/packages/fighting-utils/type/index.d.ts b/packages/fighting-components/_interface/index.d.ts similarity index 100% rename from packages/fighting-utils/type/index.d.ts rename to packages/fighting-components/_interface/index.d.ts diff --git a/packages/fighting-utils/type/install.d.ts b/packages/fighting-components/_interface/install.d.ts similarity index 100% rename from packages/fighting-utils/type/install.d.ts rename to packages/fighting-components/_interface/install.d.ts diff --git a/packages/fighting-utils/type/utils.d.ts b/packages/fighting-components/_interface/utils.d.ts similarity index 100% rename from packages/fighting-utils/type/utils.d.ts rename to packages/fighting-components/_interface/utils.d.ts diff --git a/packages/fighting-utils/type/watermark.d.ts b/packages/fighting-components/_interface/watermark.d.ts similarity index 100% rename from packages/fighting-utils/type/watermark.d.ts rename to packages/fighting-components/_interface/watermark.d.ts diff --git a/packages/fighting-utils/change-color.ts b/packages/fighting-components/_utils/change-color.ts similarity index 96% rename from packages/fighting-utils/change-color.ts rename to packages/fighting-components/_utils/change-color.ts index f40d0f3055..073b00ba51 100644 --- a/packages/fighting-utils/change-color.ts +++ b/packages/fighting-components/_utils/change-color.ts @@ -1,4 +1,4 @@ -import type { changeColorInterface } from './type' +import type { changeColorInterface } from '../_interface' /** * 根据传入的 hex 计算出加深和减淡的颜色 diff --git a/packages/fighting-utils/index.ts b/packages/fighting-components/_utils/index.ts similarity index 100% rename from packages/fighting-utils/index.ts rename to packages/fighting-components/_utils/index.ts diff --git a/packages/fighting-utils/install.ts b/packages/fighting-components/_utils/install.ts similarity index 75% rename from packages/fighting-utils/install.ts rename to packages/fighting-components/_utils/install.ts index 7cfdcc01b4..364b2069be 100644 --- a/packages/fighting-utils/install.ts +++ b/packages/fighting-components/_utils/install.ts @@ -1,4 +1,4 @@ -import type { installInterface, mainVNodeInterface } from './type' +import type { installInterface, mainVNodeInterface } from '../_interface' import type { App } from 'vue' /** @@ -15,6 +15,11 @@ export const install: installInterface = ( } } +/** + * 注册内置组件 + * @param main 组件实例 + * @param name 组件名 + */ export const installFn: installInterface = ( main: mainVNodeInterface, name: string diff --git a/packages/fighting-utils/load-image.ts b/packages/fighting-components/_utils/load-image.ts similarity index 97% rename from packages/fighting-utils/load-image.ts rename to packages/fighting-components/_utils/load-image.ts index 7619d189d6..d4960a629d 100644 --- a/packages/fighting-utils/load-image.ts +++ b/packages/fighting-components/_utils/load-image.ts @@ -4,7 +4,7 @@ import type { loadImageInterface, propsInterface, callbackInterface -} from './type' +} from '../_interface' /** * 图片加载 @@ -26,7 +26,9 @@ class Load implements LoadInterface { this.emit = emit this.callback = callback } - // 加载当前的 src 地址图片 + /** + * 加载当前的 src 地址图片 + */ loadCreateImg = (): void => { this.img.src = this.props.src diff --git a/packages/fighting-utils/ripples.ts b/packages/fighting-components/_utils/ripples.ts similarity index 92% rename from packages/fighting-utils/ripples.ts rename to packages/fighting-components/_utils/ripples.ts index 29dfbbe567..b6c0c44859 100644 --- a/packages/fighting-utils/ripples.ts +++ b/packages/fighting-components/_utils/ripples.ts @@ -1,5 +1,5 @@ -import type { RipplesInterface, buttonEventInterface } from './type' -import type { buttonType } from '../fighting-components/button/src/interface' +import type { RipplesInterface, buttonEventInterface } from '../_interface' +import type { buttonType } from '../button/src/interface' const colorList = { default: '#f0f0f0', diff --git a/packages/fighting-utils/utils.ts b/packages/fighting-components/_utils/utils.ts similarity index 98% rename from packages/fighting-utils/utils.ts rename to packages/fighting-components/_utils/utils.ts index c9b6c1e08d..c2cd1dad78 100644 --- a/packages/fighting-utils/utils.ts +++ b/packages/fighting-components/_utils/utils.ts @@ -4,7 +4,7 @@ import type { getTypeInterface as c, pastTimeInterface as d, pastTimeConfigInterface as e -} from './type' +} from '../_interface' /** * 保留小数点后 n 位 diff --git a/packages/fighting-utils/watermark.ts b/packages/fighting-components/_utils/watermark.ts similarity index 94% rename from packages/fighting-utils/watermark.ts rename to packages/fighting-components/_utils/watermark.ts index b517dab542..795259827a 100644 --- a/packages/fighting-utils/watermark.ts +++ b/packages/fighting-components/_utils/watermark.ts @@ -1,4 +1,4 @@ -import type { createBase64Interface as a } from './type' +import type { createBase64Interface as a } from '../_interface' /** * 将 canvas 转换成 base64 图片格式 diff --git a/packages/fighting-components/alert/index.ts b/packages/fighting-components/alert/index.ts index af5c8bc188..7ac8d85458 100644 --- a/packages/fighting-components/alert/index.ts +++ b/packages/fighting-components/alert/index.ts @@ -1,7 +1,7 @@ import FAlert from './src/alert.vue' -import { install } from '@fighting-design/fighting-utils' +import { install } from '../_utils' install(FAlert, FAlert.name) -export { FAlert } +export default FAlert diff --git a/packages/fighting-components/aside/index.ts b/packages/fighting-components/aside/index.ts index 5f180cf1e1..ec6b0faab8 100644 --- a/packages/fighting-components/aside/index.ts +++ b/packages/fighting-components/aside/index.ts @@ -1,7 +1,7 @@ import FAside from './src/aside.vue' -import { install } from '@fighting-design/fighting-utils' +import { install } from '../_utils' install(FAside, FAside.name) -export { FAside } +export default FAside diff --git a/packages/fighting-components/avatar/index.ts b/packages/fighting-components/avatar/index.ts index 68c52f2159..b2441d0b0d 100644 --- a/packages/fighting-components/avatar/index.ts +++ b/packages/fighting-components/avatar/index.ts @@ -1,7 +1,7 @@ import FAvatar from './src/avatar.vue' -import { install } from '@fighting-design/fighting-utils' +import { install } from '../_utils' install(FAvatar, FAvatar.name) -export { FAvatar } +export default FAvatar diff --git a/packages/fighting-components/avatar/src/avatar.vue b/packages/fighting-components/avatar/src/avatar.vue index 94a117f330..289c5a75c2 100644 --- a/packages/fighting-components/avatar/src/avatar.vue +++ b/packages/fighting-components/avatar/src/avatar.vue @@ -1,11 +1,7 @@ - + diff --git a/vite.config.demo.ts b/vite.config.demo.ts index 818f906743..552ff8aad9 100644 --- a/vite.config.demo.ts +++ b/vite.config.demo.ts @@ -1,47 +1,73 @@ +/* eslint-disable import/extensions */ +/* eslint-disable import/no-unresolved */ import type { UserConfigExport } from 'vite' import vue from '@vitejs/plugin-vue' +import vueSetupExtend from 'unplugin-vue-setup-extend-plus/vite' +import { resolve } from 'path' +import dts from 'vite-plugin-dts' +import Components from 'unplugin-vue-components/vite' + +const input: string = resolve( + __dirname, + 'packages/fighting-components/index.ts' +) export default (): UserConfigExport => { return { + mode: 'production', build: { target: 'modules', - // 打包文件目录 - outDir: 'es', + // outDir: 'es', // 打包文件目录 // 压缩 minify: false, + emptyOutDir: false, + chunkSizeWarningLimit: 2, // 超过 2kb 警告提示 + reportCompressedSize: false, + outDir: resolve(__dirname, 'dist/es'), // css分离 // cssCodeSplit: true, rollupOptions: { // 忽略打包vue文件 external: ['vue'], - input: ['src/index.ts'], + input, output: [ { format: 'es', + dir: 'dist/es', // 不用打包成.es.js,这里我们想把它打包成.js entryFileNames: '[name].js', // 让打包目录和我们目录对应 preserveModules: true, // 配置打包根目录 - dir: 'es', - preserveModulesRoot: 'src' + preserveModulesRoot: 'components' }, { format: 'cjs', + dir: 'dist/lib', entryFileNames: '[name].js', // 让打包目录和我们目录对应 preserveModules: true, // 配置打包根目录 - dir: 'lib', - preserveModulesRoot: 'src' + preserveModulesRoot: 'components' } ] }, lib: { - entry: './index.ts', + entry: input, formats: ['es', 'cjs'] } }, - plugins: [vue()] + plugins: [ + vueSetupExtend(), + vue(), + dts({ + insertTypesEntry: true, + copyDtsFiles: true, + cleanVueFileName: true + }), + Components({ + dts: resolve(__dirname, '/packages/fighting-components/components.d.ts') + }) + ] } } diff --git a/vite.config.lib.ts b/vite.config.lib.ts index f66a053bac..a30b6759ca 100644 --- a/vite.config.lib.ts +++ b/vite.config.lib.ts @@ -1,38 +1,43 @@ +/* eslint-disable import/extensions */ +/* eslint-disable import/no-unresolved */ import type { UserConfigExport } from 'vite' import vue from '@vitejs/plugin-vue' +import vueSetupExtend from 'unplugin-vue-setup-extend-plus/vite' import { resolve } from 'path' import dts from 'vite-plugin-dts' -import vueSetupExtend from 'unplugin-vue-setup-extend-plus/vite' +import Components from 'unplugin-vue-components/vite' + +const input: string = resolve( + __dirname, + 'packages/fighting-components/index.ts' +) export default (): UserConfigExport => { return { - plugins: [ - vueSetupExtend(), - vue(), - dts({ - insertTypesEntry: true, - copyDtsFiles: true, - cleanVueFileName: true - }) - ], + mode: 'production', build: { + target: 'modules', + minify: false, + emptyOutDir: false, + chunkSizeWarningLimit: 2, + reportCompressedSize: false, outDir: resolve(__dirname, 'dist/lib'), - lib: { - entry: resolve(__dirname, 'packages/fighting-design/index.d.ts'), - formats: ['cjs'], - fileName: (target) => { - return `index.${target}.js` - } - }, rollupOptions: { external: ['vue'], - preserveModules: true, - output: { - format: 'cjs', - globals: { - vue: 'Vue' + input, + output: [ + { + format: 'cjs', + dir: 'dist/lib', + entryFileNames: '[name].js', + preserveModules: true, + preserveModulesRoot: 'components' } - } + ] + }, + lib: { + entry: input, + formats: ['cjs'] }, terserOptions: { compress: { @@ -40,6 +45,18 @@ export default (): UserConfigExport => { drop_debugger: true } } - } + }, + plugins: [ + vueSetupExtend(), + vue(), + dts({ + insertTypesEntry: true, + copyDtsFiles: true, + cleanVueFileName: true + }), + Components({ + dts: resolve(__dirname, '/packages/fighting-components/components.d.ts') + }) + ] } } diff --git a/vite.config.ts b/vite.config.ts index a61f94dd8c..a335d5ad5c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,48 +7,56 @@ import { resolve } from 'path' import dts from 'vite-plugin-dts' import Components from 'unplugin-vue-components/vite' +const input: string = resolve( + __dirname, + 'packages/fighting-components/index.ts' +) + export default (): UserConfigExport => { return { - plugins: [ - vueSetupExtend(), - vue(), - dts({ - insertTypesEntry: true, - copyDtsFiles: true, - cleanVueFileName: true - }), - Components({ - dts: resolve(__dirname, '/packages/fighting-components/components.d.ts') - }) - ], + mode: 'production', build: { + target: 'modules', + minify: false, // 压缩 + emptyOutDir: false, chunkSizeWarningLimit: 2, // 超过 2kb 警告提示 reportCompressedSize: false, outDir: resolve(__dirname, 'dist/es'), - lib: { - entry: resolve(__dirname, 'packages/fighting-design/index.d.ts'), - formats: ['es'], - fileName: (target): string => { - return `index.${target}.js` - } - }, rollupOptions: { - external: ['vue'], - preserveModules: true, - output: { - format: 'es', - globals: { - vue: 'Vue' + external: ['vue'], // 忽略打包vue文件 + input, + output: [ + { + format: 'es', + dir: 'dist/es', + entryFileNames: '[name].js', + preserveModules: true, // 让打包目录和我们目录对应 + preserveModulesRoot: 'components' // 配置打包根目录 } - } + ] + }, + lib: { + entry: input, + formats: ['es'] }, terserOptions: { - // 打包取消 console 和 debugger compress: { drop_console: true, drop_debugger: true } } - } + }, + plugins: [ + vueSetupExtend(), + vue(), + dts({ + insertTypesEntry: true, + copyDtsFiles: true, + cleanVueFileName: true + }), + Components({ + dts: resolve(__dirname, '/packages/fighting-components/components.d.ts') + }) + ] } } diff --git a/vite.config.umd.ts b/vite.config.umd.ts index d216123970..a3e460ed0e 100644 --- a/vite.config.umd.ts +++ b/vite.config.umd.ts @@ -9,7 +9,7 @@ export default (): UserConfigExport => { build: { outDir: resolve(__dirname, 'dist/dist'), lib: { - entry: resolve(__dirname, 'packages/fighting-design/index.d.ts'), + entry: resolve(__dirname, 'packages/fighting-components/index.ts'), name: 'FightingDesign', formats: ['umd'], fileName: (target): string => {