@zw-team/react-lib 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +60 -29
  2. package/package.json +14 -15
package/README.md CHANGED
@@ -78,30 +78,61 @@ pnpm build:storybook# 生成静态化 Storybook(输出到 storybook-static/)
78
78
 
79
79
  ## 导出与使用方式
80
80
 
81
- ### 组件导出模式
81
+ ### 在业务项目中安装
82
82
 
83
- 组件库采用多入口点导出方式,支持按需导入:
83
+ ```bash
84
+ pnpm add @zw-team/react-lib
85
+ # 或
86
+ npm install @zw-team/react-lib
87
+ ```
88
+
89
+ 请确保业务项目已安装并满足 `package.json` 中声明的 **peerDependencies**:`react`、`react-dom`、`antd`、`@ant-design/icons`、`axios`、`dayjs`、`zustand`(版本需落在各自兼容范围内),否则可能出现重复实例、类型或运行期错误。
90
+
91
+ ### 按需引入(组件 / Hooks / Utils / Config)
92
+
93
+ 组件库采用多入口 `exports`,可按子路径按需加载:
84
94
 
85
- - **主入口**(`@zw-team/react-lib`):导出所有组件
95
+ - **主入口**(`@zw-team/react-lib`):导出组件及主题相关(不含 Hooks、Utils,见 `src/index.ts`)
86
96
  ```typescript
87
97
  import { BiAvatar, BiBlock } from '@zw-team/react-lib'
88
98
  ```
89
99
 
90
- - **组件入口**(`@zw-team/react-lib/components`):仅导出组件
100
+ - **组件入口**(`@zw-team/react-lib/components`)
91
101
  ```typescript
92
102
  import { BiAvatar, BiBlock } from '@zw-team/react-lib/components'
93
103
  ```
94
104
 
95
- - **Hooks 入口**(`@zw-team/react-lib/hooks`):导出工具 Hooks
105
+ - **Hooks 入口**(`@zw-team/react-lib/hooks`)
96
106
  ```typescript
97
107
  import { useLatest, usePermission } from '@zw-team/react-lib/hooks'
98
108
  ```
99
109
 
100
- - **工具入口**(`@zw-team/react-lib/utils`):导出工具函数
110
+ - **工具入口**(`@zw-team/react-lib/utils`)
101
111
  ```typescript
102
112
  import { request, ossUpload } from '@zw-team/react-lib/utils'
103
113
  ```
104
114
 
115
+ - **配置入口**(`@zw-team/react-lib/config`):环境枚举、服务 URL 等(以包内实际导出为准)
116
+ ```typescript
117
+ import { EnvType, getServiceURL } from '@zw-team/react-lib/config'
118
+ ```
119
+
120
+ ### 样式与 Sass(使用带 `.scss` 的组件时必读)
121
+
122
+ 部分组件在产物中仍 `import` **`.scss`** 文件,业务侧打包器必须能解析 Sass。未配置时易出现类似 `Module parse failed` / `Expression expected`(把 SCSS 当成 JS 解析)的报错。
123
+
124
+ - **Rsbuild**:安装 `@rsbuild/plugin-sass` 并在配置中注册(参考 [npm 说明](https://www.npmjs.com/package/@rsbuild/plugin-sass))。
125
+ ```typescript
126
+ import { defineConfig } from '@rsbuild/core'
127
+ import { pluginSass } from '@rsbuild/plugin-sass'
128
+
129
+ export default defineConfig({
130
+ plugins: [pluginSass()],
131
+ })
132
+ ```
133
+ - **Vite**:一般需在项目中安装 `sass`(常见做法为开发依赖)。
134
+ - **Webpack**:需配置 `sass-loader` 等以处理 `.scss`。
135
+
105
136
  ### 组件命名规范
106
137
 
107
138
  所有组件统一使用 `Bi` 前缀(如 `BiAvatar`、`BiBlock`、`BiForm`)可在组件的index.ts重新命名加上Bi,便于识别和避免命名冲突。
@@ -142,10 +173,7 @@ pnpm dev
142
173
 
143
174
  ```bash
144
175
  # 在目标项目中执行
145
- pnpm unlink @zw-team/react-lib
146
- ```
147
-
148
-
176
+ pnpm unlink @zw-team/react-lib
149
177
  ```
150
178
 
151
179
  ### 注意事项
@@ -164,37 +192,40 @@ pnpm unlink @zw-team/react-lib
164
192
 
165
193
  ## 目录结构(节选)
166
194
 
167
- ```
195
+ ```text
168
196
  .
169
- ├── .storybook/ # Storybook 工程配置
197
+ ├── .storybook/ # Storybook 工程配置
170
198
  ├── src/
171
- │ ├── components/ # 组件目录
172
- │ │ ├── Avatar/ # Avatar 组件
199
+ │ ├── components/ # 组件目录
200
+ │ │ ├── Avatar/
173
201
  │ │ │ ├── Avatar.tsx
174
- │ │ │ ├── index.ts # 导出:export { default as BiAvatar } from './Avatar'
175
- │ │ │ └── types.ts # 类型定义
176
- │ │ ├── Block/ # Block 组件
202
+ │ │ │ ├── index.ts # 如: export { default as BiAvatar } from './Avatar'
203
+ │ │ │ └── types.ts
204
+ │ │ ├── Block/
177
205
  │ │ │ ├── Block.tsx
178
206
  │ │ │ ├── Block.css
179
207
  │ │ │ ├── index.ts
180
208
  │ │ │ └── types.ts
181
- │ │ ├── ... # 其他组件
182
- │ │ └── index.ts # 组件统一导出入口
183
- │ ├── hooks/ # 工具 Hooks
209
+ │ │ ├── ...
210
+ │ │ └── index.ts # 组件统一导出
211
+ │ ├── hooks/
184
212
  │ │ ├── useLatest.ts
185
213
  │ │ ├── usePermission.ts
186
- │ │ └── index.ts # Hooks 导出入口
187
- │ ├── utils/ # 工具函数
214
+ │ │ └── index.ts
215
+ │ ├── utils/
188
216
  │ │ ├── date.ts
189
217
  │ │ ├── ossUpload.ts
190
218
  │ │ ├── request/
191
- │ │ └── index.ts # Utils 导出入口
192
- │ └── index.ts # 主入口(导出所有组件)
193
- ├── stories/ # Storybook 示例
194
- ├── dist/ # 构建后产物(由 rslib 生成)
195
- ├── rslib.config.ts # rslib 打包配置(多入口点配置)
196
- ├── biome.json # Biome 规范配置
197
- └── package.json # 包配置(exports 字段定义多入口点)
219
+ │ │ └── index.ts
220
+ │ ├── config/
221
+ │ │ ├── index.ts # 环境与服务 URL 等(@zw-team/react-lib/config)
222
+ │ │ └── theme/
223
+ │ └── index.ts # 库主入口(组件 + 主题)
224
+ ├── stories/
225
+ ├── dist/ # rslib 构建产物
226
+ ├── rslib.config.ts
227
+ ├── biome.json
228
+ └── package.json # exports 多入口
198
229
  ```
199
230
 
200
231
  ## 现有组件状态
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zw-team/react-lib",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "zw-team 业务组件库,基于 React + Ant Design,提供通用组件、Hooks 与工具函数",
5
5
  "keywords": [
6
6
  "react",
@@ -55,19 +55,6 @@
55
55
  "**/*.css",
56
56
  "**/*.scss"
57
57
  ],
58
- "scripts": {
59
- "build": "rslib build",
60
- "build:storybook": "storybook build",
61
- "check": "biome check --write",
62
- "dev": "rslib build --watch",
63
- "format": "biome format --write",
64
- "lint": "biome lint",
65
- "prepublishOnly": "npm run build",
66
- "release:patch": "npm version patch && npm publish",
67
- "release:minor": "npm version minor && npm publish",
68
- "release:major": "npm version major && npm publish",
69
- "storybook": "storybook dev --host frontend.zwwlkj03.top --port 8080"
70
- },
71
58
  "dependencies": {
72
59
  "@braintree/event-emitter": "2.0.2",
73
60
  "ali-oss": "^6.23.0",
@@ -112,5 +99,17 @@
112
99
  "storybook-react-rsbuild": "2.1.4",
113
100
  "typescript": "5.9.3",
114
101
  "zustand": "^5.0.10"
102
+ },
103
+ "scripts": {
104
+ "build": "rslib build",
105
+ "build:storybook": "storybook build",
106
+ "check": "biome check --write",
107
+ "dev": "rslib build --watch",
108
+ "format": "biome format --write",
109
+ "lint": "biome lint",
110
+ "release:patch": "npm version patch && npm publish",
111
+ "release:minor": "npm version minor && npm publish",
112
+ "release:major": "npm version major && npm publish",
113
+ "storybook": "storybook dev --host frontend.zwwlkj03.top --port 8080"
115
114
  }
116
- }
115
+ }