diff --git a/packages/ui-react/package.json b/packages/ui-react/package.json index ad7549b..82505ba 100644 --- a/packages/ui-react/package.json +++ b/packages/ui-react/package.json @@ -13,22 +13,13 @@ "docs/[^.]*", "doc/[^.]*" ], + "module": "index.js", "typings": "index.d.ts", "exports": { - ".": { - "import": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" - }, - "require": { - "types": "./dist/index.d.ts", - "default": "./dist/index.cjs.js" - } - }, "./index.css": "./dist/index.css" }, "scripts": { - "build": "tsc --project tsconfig.build.json" + "build": "vite build && tsc --project tsconfig.build.json" }, "dependencies": { "@floating-ui/react": "^0.27.20", @@ -37,7 +28,22 @@ "devDependencies": { "@types/node": "^26.6.6", "@types/react": "^19.3.0", - "@types/react-dom": "^19.3.0" + "@types/react-dom": "^19.3.0", + "@babel/core": "^7.29.13", + "@eslint/js": "^10.0.1", + "@rolldown/plugin-babel": "^0.3.1", + "@types/babel__core": "^7.20.5", + "@vitejs/devtools": "^0.8.3", + "@vitejs/devtools-rolldown": "^0.8.3", + "@vitejs/devtools-vite": "^0.8.3", + "@vitejs/plugin-react": "^6.3.0", + "babel-plugin-react-compiler": "^1.0.0", + "eslint": "^10.15.0", + "eslint-plugin-react-hooks": "^7.1.1", + "eslint-plugin-react-refresh": "^0.5.8", + "globals": "^17.14.0", + "typescript": "~6.0.3", + "typescript-eslint": "^8.73.0" }, "peerDependencies": { "react": "^19.3.1", diff --git a/packages/ui-react/tsconfig.json b/packages/ui-react/tsconfig.json index 35b2f1e..87a82a6 100644 --- a/packages/ui-react/tsconfig.json +++ b/packages/ui-react/tsconfig.json @@ -9,10 +9,12 @@ "module": "esnext", // 所有项目必须开,兼容 es 和 cjs 导入,允许 import React from 'react' ,而非 import * as React 。 "esModuleInterop": true, - // 允许导入 ts,tsx 扩展名,include 里可以省略后缀。 + // 允许导入 ts,tsx 扩展名。 "allowImportingTsExtensions": true, - // 允许 js,jsx 扩展名,include 里可以省略后缀。 + // 允许导入 js,jsx 扩展名。 "allowJs": true, + // 允许导入 json 模块,而不只是 ts,js,css 。 + "resolveJsonModule": true, // 启用装饰器,也就是 @XXX 注解。 "experimentalDecorators": true, // 发射装饰器元数据。 @@ -37,7 +39,7 @@ "incremental": true }, // 本配置文件的作用范围,包含根目录下的一切文件,包括 vite.config.ts 等配置文件 - "include": ["**/*.ts",], + "include": ["**/*.ts", "*/*.tsx"], // 本配置文件排除的范围。 "exclude": [ "node_modules", diff --git a/packages/ui-react/vite.config.ts b/packages/ui-react/vite.config.ts new file mode 100644 index 0000000..d7e1efb --- /dev/null +++ b/packages/ui-react/vite.config.ts @@ -0,0 +1,38 @@ +import react, { reactCompilerPreset } from "@vitejs/plugin-react"; +import babel from "@rolldown/plugin-babel"; +import { defineConfig } from "vite"; +import { resolve } from "path"; +import pkg from "./package.json" with { type: "json" }; + +// https://vite.dev/config/ +export default defineConfig({ + devtools: { + // Remove this `apply` property to enable devtools for build as well + // apply: 'serve', + }, + plugins: [react(), babel({ presets: [reactCompilerPreset()] })], + + build: { + // Must write, vite/css-minify cannot recognize some ruler + cssMinify: false, + lib: { + entry: resolve(import.meta.dirname, "src/index.ts"), + name: "ui-react", + formats: ["es"], + fileName: (format) => { + return `index.${format}.js`; + }, + cssFileName: "index", + }, + rolldownOptions: { + external: ["react/jsx-runtime", ...Object.keys(pkg.peerDependencies)], + output: { + // 为 UMD 构建提供 global 变量 + globals: { + react: "React", + "react-dom": "ReactDOM", + }, + }, + }, + }, +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3f78ab8..498e71a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -93,6 +93,18 @@ importers: specifier: ^5.4.0 version: 5.4.0(react-dom@19.3.1(react@19.3.1))(react@19.3.1) devDependencies: + '@babel/core': + specifier: ^7.29.13 + version: 7.29.13 + '@eslint/js': + specifier: ^10.0.1 + version: 10.0.1(eslint@10.15.0) + '@rolldown/plugin-babel': + specifier: ^0.3.1 + version: 0.3.2(@babel/core@7.29.13)(rolldown@1.3.4)(vite@8.4.0) + '@types/babel__core': + specifier: ^7.20.5 + version: 7.20.5 '@types/node': specifier: ^26.6.6 version: 26.6.11 @@ -102,6 +114,39 @@ importers: '@types/react-dom': specifier: ^19.3.0 version: 19.3.0(@types/react@19.3.3) + '@vitejs/devtools': + specifier: ^0.8.3 + version: 0.8.3(@vitejs/devtools-rolldown@0.8.3)(@vitejs/devtools-vite@0.8.3)(crossws@0.4.17(srvx@1.0.8))(srvx@1.0.8)(vite@8.4.0) + '@vitejs/devtools-rolldown': + specifier: ^0.8.3 + version: 0.8.3(@devframes/agentic@1.4.0)(cac@7.1.1)(crossws@0.4.17(srvx@1.0.8))(srvx@1.0.8)(vite@8.4.0) + '@vitejs/devtools-vite': + specifier: ^0.8.3 + version: 0.8.3(@devframes/agentic@1.4.0)(cac@7.1.1)(crossws@0.4.17(srvx@1.0.8))(srvx@1.0.8)(vite@8.4.0) + '@vitejs/plugin-react': + specifier: ^6.3.0 + version: 6.3.0(@rolldown/plugin-babel@0.3.2(@babel/core@7.29.13)(rolldown@1.3.4)(vite@8.4.0))(babel-plugin-react-compiler@1.0.0)(vite@8.4.0) + babel-plugin-react-compiler: + specifier: ^1.0.0 + version: 1.0.0 + eslint: + specifier: ^10.15.0 + version: 10.15.0 + eslint-plugin-react-hooks: + specifier: ^7.1.1 + version: 7.1.1(eslint@10.15.0) + eslint-plugin-react-refresh: + specifier: ^0.5.8 + version: 0.5.8(eslint@10.15.0) + globals: + specifier: ^17.14.0 + version: 17.14.0 + typescript: + specifier: ~6.0.3 + version: 6.0.3 + typescript-eslint: + specifier: ^8.73.0 + version: 8.74.0(eslint@10.15.0)(typescript@6.0.3) packages: