diff --git a/packages/cli/src/utils/resolveAppPackages.ts b/packages/cli/src/utils/resolveAppPackages.ts index 67387ad2..dee9d367 100644 --- a/packages/cli/src/utils/resolveAppPackages.ts +++ b/packages/cli/src/utils/resolveAppPackages.ts @@ -190,6 +190,18 @@ const getAssertionTokenByTraverse = (ast: any) => { variableDeclarations.push(p.node); this.traverse(p); }, + visitExportNamedDeclaration(p) { + const { node } = p; + const { specifiers } = node; + + const specifier = specifiers?.find((specifier) => specifier.exported.name === 'default'); + + if (specifier?.local) { + exportDefaultName = `${specifier.local.name}`; + } + + this.traverse(p); + }, visitExportDefaultDeclaration(p) { const { node } = p; const { declaration } = node; diff --git a/packages/ui-vue2/src/index.ts b/packages/ui-vue2/src/index.ts index 28c846bc..6ae8cc97 100644 --- a/packages/ui-vue2/src/index.ts +++ b/packages/ui-vue2/src/index.ts @@ -27,6 +27,17 @@ import PageFragmentContainer from './page-fragment-container'; import QRcode from './qrcode'; import Text from './text'; +export { default as TMagicUiButton } from './button'; +export { default as TMagicUiContainer } from './container'; +export { default as TMagicUiImg } from './img'; +export { default as TMagicUiIteratorContainer } from './iterator-container'; +export { default as TMagicUiPage } from './page'; +export { default as TMagicUiPageFragment } from './page-fragment'; +export { default as TMagicUiPageFragmentContainer } from './page-fragment-container'; +export { default as TMagicUiPageText } from './text'; + +export { default as useApp } from './useApp'; + const ui: Record = { page: Page, container: Container, diff --git a/packages/ui/package.json b/packages/ui/package.json index 29746b60..2331cd68 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -3,9 +3,21 @@ "name": "@tmagic/ui", "type": "module", "main": "src/index.ts", + "types": "types/index.d.ts", + "exports": { + "./*": "./*" + }, "files": [ - "src" + "src", + "dist", + "types" ], + "scripts": { + "build": "rimraf ./dist && npm run build:type && node scripts/build.mjs", + "build:type": "npm run clear:type && vue-tsc --declaration --emitDeclarationOnly --project tsconfig.build.json", + "clear:type": "rimraf ./types", + "check:type": "vue-tsc --noEmit --project tsconfig.build.json" + }, "engines": { "node": ">=18" }, @@ -15,14 +27,13 @@ "url": "https://github.com/Tencent/tmagic-editor.git" }, "dependencies": { - "delegate": "^3.2.0", - "qrcode": "^1.5.0", - "tiny-emitter": "^2.1.0" + "qrcode": "^1.5.0" }, "peerDependencies": { "@tmagic/core": "workspace:*", "@tmagic/schema": "workspace:*", "@tmagic/utils": "workspace:*", + "@tmagic/vue-runtime-help": ">=0.0.5", "vue": ">=3.4.27", "typescript": "*" }, @@ -32,9 +43,10 @@ } }, "devDependencies": { - "@testing-library/vue": "^6.4.2", "@types/qrcode": "^1.4.2", "@vue/compiler-sfc": "^3.4.27", - "@vue/test-utils": "^2.4.6" + "rimraf": "^3.0.2", + "vite": "^5.2.12", + "vue-tsc": "^2.0.19" } } diff --git a/packages/ui/scripts/build.mjs b/packages/ui/scripts/build.mjs new file mode 100644 index 00000000..a193c874 --- /dev/null +++ b/packages/ui/scripts/build.mjs @@ -0,0 +1,120 @@ +import { build } from 'vite'; +import vue from '@vitejs/plugin-vue'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import pkg from '../package.json' assert { type: 'json' }; + +const __dirname = fileURLToPath(new URL('.', import.meta.url)); + +const packages = [ + 'button', + 'container', + 'img', + 'iterator-container', + 'overlay', + 'page', + 'page-fragment', + 'page-fragment-container', + 'qrcode', + 'text', +]; + +const commonConfig = { + optimizeDeps: { + esbuildOptions: { + define: { + global: 'globalThis', + }, + }, + }, + + build: { + cssCodeSplit: false, + sourcemap: false, + minify: false, + target: 'esnext', + + rollupOptions: { + output: { + // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量 + globals: { + vue: 'Vue', + }, + }, + }, + }, +}; + +const main = async () => { + await build({ + ...commonConfig, + + root: path.resolve(__dirname, `../`), + + build: { + ...commonConfig.build, + outDir: `./dist`, + lib: { + entry: './src/index.ts', + name: 'ui', + fileName: 'index', + formats: ['es'], + }, + + rollupOptions: { + ...commonConfig.build.rollupOptions, + + // 确保外部化处理那些你不想打包进库的依赖 + external(id) { + return ( + Object.keys({ + ...(pkg.devDependencies || {}), + ...(pkg.peerDependencies || {}), + }).some((k) => new RegExp(`^${k}`).test(id)) || + `${id}`.startsWith('.') || + (`${id}`.startsWith('/') && !id.endsWith('/index.ts')) + ); + }, + }, + }, + }); + + packages.map((packageName) => { + const config = { + ...commonConfig, + + plugins: [vue()], + + root: path.resolve(__dirname, `../src/${packageName}`), + + build: { + ...commonConfig.build, + outDir: `../../dist/${packageName}`, + lib: { + entry: './index.ts', + name: packageName, + fileName: 'index', + formats: ['es'], + }, + + rollupOptions: { + ...commonConfig.build.rollupOptions, + + // 确保外部化处理那些你不想打包进库的依赖 + external(id) { + return ( + Object.keys({ + ...(pkg.devDependencies || {}), + ...(pkg.peerDependencies || {}), + }).some((k) => new RegExp(`^${k}`).test(id)) || `${id}`.endsWith('./container') + ); + }, + }, + }, + }; + return build(config); + }); +}; + +main(); diff --git a/packages/ui/src/button/src/index.vue b/packages/ui/src/button/src/index.vue index 57f7aba6..15850e5b 100644 --- a/packages/ui/src/button/src/index.vue +++ b/packages/ui/src/button/src/index.vue @@ -8,8 +8,7 @@