diff --git a/packages/all.ts b/packages/all.ts new file mode 100644 index 0000000..f37b128 --- /dev/null +++ b/packages/all.ts @@ -0,0 +1,17 @@ +import * as componets from '@princess-ui/components' +import type { App } from 'vue' + +export * from '@princess-ui/components' +export * from '@princess-ui/hooks' + +function install(app: App) { + for (const key in componets) { + const component = componets[key] + app.component(component.name || 'ps-' + key, component) + } +} + +export { install } +export default { + install, +} diff --git a/packages/build/build.ts b/packages/build/build.ts index 85bb06d..34a3c70 100644 --- a/packages/build/build.ts +++ b/packages/build/build.ts @@ -7,9 +7,15 @@ import buildComponent from "./buildComponent" import buildAll from "./buildAll" import { getOutput, getPath, getPkgs } from "@princess-ui/share" +import * as dts from "dts-bundle" +import pkg from "../princess-ui/package.json" + +console.log(chalk.yellow(`当前工作目录:${process.cwd()}`)) +const oldCwdFn = process.cwd process.cwd = ()=>{ return getPkgs() } +console.log(chalk.yellow(`修改后工作目录:${process.cwd()}`)) console.log(chalk.yellow("正在清除lib文件夹")) rimraf(getOutput("lib"), async err => { if (err) throw err @@ -29,7 +35,18 @@ rimraf(getOutput("lib"), async err => { console.log(chalk.yellow("构建全量包")) await buildAll("ps") console.log(chalk.green(`构建全量包完成, 其耗时:${(new Date().getTime() - beginDate) / 1000}s`)) - process.cwd = ()=>{ - return getPath() + + console.log(chalk.red("构建完成,开始生成d.ts")) + const dtsOptions = { + name: pkg.name, + main: `princess-ui/lib/packages/all.d.ts`, + out: `../index.d.ts`, + outputAsModuleFolder: true } + dts.bundle(dtsOptions) + console.log(chalk.red("生成完毕,开始清理残余")) + rimraf.sync(getOutput('lib/packages')) + console.log(chalk.green("残余清理完毕")) + process.cwd = oldCwdFn + console.log(chalk.yellow(`工作目录重置为:${process.cwd()}`)) }) diff --git a/packages/build/buildAll.ts b/packages/build/buildAll.ts index aef1d61..ddea21f 100644 --- a/packages/build/buildAll.ts +++ b/packages/build/buildAll.ts @@ -9,13 +9,18 @@ import { getOutput, getPath, getPkgs } from "@princess-ui/share"; export default function (name: string) { return build({ logLevel: "error", + resolve: { + alias: { + "@princess-ui": getPkgs(), + } + }, plugins: [ replaceCodePlugin({ replacements: [ - { - from: "@princess-ui/components", - to: "../", - }, + // { + // from: "@princess-ui/components", + // to: "../", + // }, // { // from: /\@princess\-ui\/theme-chalk\/src\/(.*?)\.scss/i, // to: "princess-ui/theme-chalk/$1.css" @@ -25,11 +30,10 @@ export default function (name: string) { vue({ isProduction: true }), vueJsx(), dts({ - entryRoot: `components`, tsConfigFilePath: getPath("tsconfig.json"), outputDir: getOutput("lib"), cleanVueFileName: true, - include: ['components/index.ts', 'components/components.ts'], + include: ['all.ts', "hooks", "components"], staticImport: true, }), ], @@ -37,7 +41,7 @@ export default function (name: string) { outDir: getOutput("lib"), emptyOutDir: false, lib: { - entry: path.resolve(__dirname, `../components/index.ts`), + entry: getPkgs(`all.ts`), name: name, formats: ["es", "umd"], fileName: format => `index${format=='es'?'':'.umd'}.js`, diff --git a/packages/build/package.json b/packages/build/package.json index d714ff4..5fe5d65 100644 --- a/packages/build/package.json +++ b/packages/build/package.json @@ -22,5 +22,8 @@ "vite-plugin-dts": "^1.1.1", "vite-plugin-replace": "^0.1.1", "vue": "^3.2.36" + }, + "dependencies": { + "dts-bundle": "^0.7.3" } } diff --git a/packages/build/tsconfig.json b/packages/build/tsconfig.json index 301d75e..3956f25 100644 --- a/packages/build/tsconfig.json +++ b/packages/build/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "allowSyntheticDefaultImports": true, "esModuleInterop": true, + "resolveJsonModule": true, "module": "commonjs", "lib": ["ES6", "DOM"], "declaration": false, diff --git a/packages/components/captcha/captcha.vue b/packages/components/captcha/captcha.vue index 33592c0..479e2c5 100644 --- a/packages/components/captcha/captcha.vue +++ b/packages/components/captcha/captcha.vue @@ -6,10 +6,12 @@ :loading="isLoading" type="button" size="small"> {{ text }} + asd