From acce2c991eeddffcab5e31f8cb0f40a7983674b1 Mon Sep 17 00:00:00 2001 From: xion Date: Sat, 2 Nov 2024 00:59:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9stystem-ui=E7=9A=84?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ui/config/rollup.components.config.js | 64 +++++++++++++++++++++ apps/ui/package.json | 5 +- apps/ui/rollup.config.js | 60 ++++++++++++-------- pnpm-lock.yaml | 66 ++++++++++++++++++++++ 4 files changed, 171 insertions(+), 24 deletions(-) create mode 100644 apps/ui/config/rollup.components.config.js diff --git a/apps/ui/config/rollup.components.config.js b/apps/ui/config/rollup.components.config.js new file mode 100644 index 0000000..7517931 --- /dev/null +++ b/apps/ui/config/rollup.components.config.js @@ -0,0 +1,64 @@ +import resolve from '@rollup/plugin-node-resolve'; +import typescript from '@rollup/plugin-typescript'; +import commonjs from '@rollup/plugin-commonjs'; +import postcss from 'rollup-plugin-postcss'; +import autoprefixer from 'autoprefixer'; +import cssnano from 'cssnano'; +import terser from '@rollup/plugin-terser'; + +import postcssImport from 'postcss-import'; +import dts from 'rollup-plugin-dts'; + +import * as glob from 'glob'; +import path from 'path'; +const isApps = process.env.TYPE === 'apps'; +const components = glob.sync('./src/components/**/index.ts'); +const entrys = components.map((entry) => { + return entry; +}); +console.log('entry', entrys); +const output = path.resolve('./dist'); +console.log('output', output); +/** + * @type {import('rollup').RollupOptions[]} + */ +const configs = entrys + .map((entry) => { + const directory = path.dirname(entry); + const lastDirectory = directory.split('/').pop(); + const input = path.resolve(entry); + const buildConfig = { + input: input, // 修改输入文件为 TypeScript 文件 + output: { + file: path.join(output, `./${lastDirectory}.js`), + format: 'es', // 输出格式为 ES Module + }, + plugins: [ + resolve({ + browser: true, // 处理浏览器版本的依赖 + }), + commonjs(), + typescript({ + tsconfig: './tsconfig.json', + compilerOptions: { + declaration: false, // 生成声明文件 + declarationDir: './dist', // 声明文件输出目录 + // outDir: './types', // + }, + }), // 添加 TypeScript 插件 + // terser(), // 压缩输出的 ES Module 文件 + ], + }; + const tsConfig = { + input: input, + output: { + file: path.join(output, `./${lastDirectory}.d.ts`), + format: 'esm', + }, + plugins: [dts()], + }; + return [buildConfig, tsConfig]; + }) + .flat(); + +export default [...configs]; diff --git a/apps/ui/package.json b/apps/ui/package.json index 22da953..c1af162 100644 --- a/apps/ui/package.json +++ b/apps/ui/package.json @@ -8,7 +8,8 @@ "scripts": { "dev": "rollup -c -w", "build": "npm run clean && rollup -c", - "pub": "envision switchOrg system && envision deploy ./deploy -v 0.0.1 -k ui -y y", + "build:components": "rollup -c ./config/rollup.components.config.js", + "pub": "envision switchOrg system && envision deploy ./dist -v 0.0.2 -k ui -y y", "clean": "rimraf dist" }, "files": [ @@ -21,7 +22,9 @@ "license": "MIT", "dependencies": { "dayjs": "^1.11.13", + "glob": "^11.0.0", "lodash-es": "^4.17.21", + "rollup-plugin-dts": "^6.1.1", "style-to-object": "^1.0.8" }, "devDependencies": { diff --git a/apps/ui/rollup.config.js b/apps/ui/rollup.config.js index d899894..4765fa6 100644 --- a/apps/ui/rollup.config.js +++ b/apps/ui/rollup.config.js @@ -5,7 +5,7 @@ import postcss from 'rollup-plugin-postcss'; import autoprefixer from 'autoprefixer'; import cssnano from 'cssnano'; import terser from '@rollup/plugin-terser'; - +import dts from 'rollup-plugin-dts'; import postcssImport from 'postcss-import'; const isApps = process.env.TYPE === 'apps'; @@ -13,29 +13,43 @@ const entrys = ['index']; /** * @type {import('rollup').RollupOptions[]} */ -const configs = entrys.map((entry) => ({ - input: `./src/${entry}.ts`, // 修改输入文件为 TypeScript 文件 - output: { - file: `./dist/${entry}.js`, - // dir: 'dist', - format: 'es', // 输出格式为 ES Module - }, - plugins: [ - resolve({ - browser: true, // 处理浏览器版本的依赖 - }), - commonjs(), - typescript({ - tsconfig: './tsconfig.json', - compilerOptions: { - declaration: !isApps, // 生成声明文件 - declarationDir: './dist', // 声明文件输出目录 - // outDir: './types', // +const configs = entrys + .map((entry) => { + const buildConfig = { + input: `./src/${entry}.ts`, // 修改输入文件为 TypeScript 文件 + output: { + file: `./dist/${entry}.js`, + // dir: 'dist', + format: 'es', // 输出格式为 ES Module }, - }), // 添加 TypeScript 插件 - terser(), // 压缩输出的 ES Module 文件 - ], -})); + plugins: [ + resolve({ + browser: true, // 处理浏览器版本的依赖 + }), + commonjs(), + typescript({ + tsconfig: './tsconfig.json', + compilerOptions: { + // declaration: !isApps, // 生成声明文件 + declaration: false, // 生成声明文件 + declarationDir: './dist', // 声明文件输出目录 + // outDir: './types', // + }, + }), // 添加 TypeScript 插件 + terser(), // 压缩输出的 ES Module 文件 + ], + }; + const dtsConfig = { + input: `./src/${entry}.ts`, + output: { + file: `./dist/${entry}.d.ts`, + format: 'esm', + }, + plugins: [dts()], + }; + return [buildConfig, dtsConfig]; + }) + .flat(); const entryCss = ['index']; const configsCss = entryCss.map((entry) => ({ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5ea5056..d97567d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,9 +74,15 @@ importers: dayjs: specifier: ^1.11.13 version: 1.11.13 + glob: + specifier: ^11.0.0 + version: 11.0.0 lodash-es: specifier: ^4.17.21 version: 4.17.21 + rollup-plugin-dts: + specifier: ^6.1.1 + version: 6.1.1(rollup@4.24.0)(typescript@5.6.3) style-to-object: specifier: ^1.0.8 version: 1.0.8 @@ -1792,6 +1798,11 @@ packages: resolution: {integrity: sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==} hasBin: true + glob@11.0.0: + resolution: {integrity: sha512-9UiX/Bl6J2yaBbxKoEBRm4Cipxgok8kQYcOPEhScPwebu2I0HoQOuYdIO6S3hLuWoZgpDpwQZMzTFxgpkyT76g==} + engines: {node: 20 || >=22} + hasBin: true + gopd@1.0.1: resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} @@ -1981,6 +1992,10 @@ packages: jackspeak@3.4.3: resolution: {integrity: sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==} + jackspeak@4.0.2: + resolution: {integrity: sha512-bZsjR/iRjl1Nk1UkjGpAzLNfQtzuijhn2g+pbZb98HQ1Gk8vM9hfbxeMBP+M2/UUdwj0RqGG3mlvk2MsAqwvEw==} + engines: {node: 20 || >=22} + jest-worker@27.5.1: resolution: {integrity: sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==} engines: {node: '>= 10.13.0'} @@ -2059,6 +2074,10 @@ packages: lru-cache@10.4.3: resolution: {integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==} + lru-cache@11.0.2: + resolution: {integrity: sha512-123qHRfJBmo2jXDbo/a5YOQrJoHF/GNQTLzQ5+IdK5pWpceK17yRc6ozlWd25FxvGKQbIUs91fDFkXmDHTKcyA==} + engines: {node: 20 || >=22} + lz-string@1.5.0: resolution: {integrity: sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==} hasBin: true @@ -2136,6 +2155,10 @@ packages: peerDependencies: webpack: ^5.0.0 + minimatch@10.0.1: + resolution: {integrity: sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==} + engines: {node: 20 || >=22} + minimatch@3.1.2: resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} @@ -2267,6 +2290,10 @@ packages: resolution: {integrity: sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==} engines: {node: '>=16 || 14 >=14.18'} + path-scurry@2.0.0: + resolution: {integrity: sha512-ypGJsmGtdXUOeM5u93TyeIEfEhM6s+ljAhrk5vAvSx8uyY/02OvrZnA0YNGUrPXfpJMgI1ODd3nwz8Npx4O4cg==} + engines: {node: 20 || >=22} + path-to-regexp@0.1.10: resolution: {integrity: sha512-7lf7qcQidTku0Gu3YDPc8DJ1q7OOucfa/BSsIwjuh56VU7katFvuM8hULfkwB3Fns/rsVF7PwPKVw1sl5KQS9w==} @@ -2852,6 +2879,13 @@ packages: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} + rollup-plugin-dts@6.1.1: + resolution: {integrity: sha512-aSHRcJ6KG2IHIioYlvAOcEq6U99sVtqDDKVhnwt70rW6tsz3tv5OSjEiWcgzfsHdLyGXZ/3b/7b/+Za3Y6r1XA==} + engines: {node: '>=16'} + peerDependencies: + rollup: ^3.29.4 || ^4 + typescript: ^4.5 || ^5.0 + rollup-plugin-postcss@4.0.2: resolution: {integrity: sha512-05EaY6zvZdmvPUDi3uCcAQoESDcYnv8ogJJQRp6V5kZ6J6P7uAVJlrTZcaaA20wTH527YTnKfkAoPxWI/jPp4w==} engines: {node: '>=10'} @@ -5056,6 +5090,15 @@ snapshots: package-json-from-dist: 1.0.1 path-scurry: 1.11.1 + glob@11.0.0: + dependencies: + foreground-child: 3.3.0 + jackspeak: 4.0.2 + minimatch: 10.0.1 + minipass: 7.1.2 + package-json-from-dist: 1.0.1 + path-scurry: 2.0.0 + gopd@1.0.1: dependencies: get-intrinsic: 1.2.4 @@ -5229,6 +5272,10 @@ snapshots: optionalDependencies: '@pkgjs/parseargs': 0.11.0 + jackspeak@4.0.2: + dependencies: + '@isaacs/cliui': 8.0.2 + jest-worker@27.5.1: dependencies: '@types/node': 22.7.6 @@ -5289,6 +5336,8 @@ snapshots: lru-cache@10.4.3: {} + lru-cache@11.0.2: {} + lz-string@1.5.0: {} magic-string@0.30.12: @@ -5346,6 +5395,10 @@ snapshots: tapable: 2.2.1 webpack: 5.95.0(@swc/core@1.7.36)(esbuild@0.23.1) + minimatch@10.0.1: + dependencies: + brace-expansion: 2.0.1 + minimatch@3.1.2: dependencies: brace-expansion: 1.1.11 @@ -5458,6 +5511,11 @@ snapshots: lru-cache: 10.4.3 minipass: 7.1.2 + path-scurry@2.0.0: + dependencies: + lru-cache: 11.0.2 + minipass: 7.1.2 + path-to-regexp@0.1.10: {} path-type@4.0.0: {} @@ -6003,6 +6061,14 @@ snapshots: reusify@1.0.4: {} + rollup-plugin-dts@6.1.1(rollup@4.24.0)(typescript@5.6.3): + dependencies: + magic-string: 0.30.12 + rollup: 4.24.0 + typescript: 5.6.3 + optionalDependencies: + '@babel/code-frame': 7.25.7 + rollup-plugin-postcss@4.0.2(postcss@8.4.47): dependencies: chalk: 4.1.2