@weitutech/by-components 1.1.18 → 1.1.19

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.
package/README.md CHANGED
@@ -52,6 +52,20 @@ npm publish --access public
52
52
  项目中运行 npm link @weitutech/by-components
53
53
  ```
54
54
 
55
+ > **💡 提示**
56
+ > 本地link调试时,需要把组件库的package.json中的main字段改为src/index.js("main": "src/index.js")
57
+ > 调试完成后,切记改回 "main": "lib/by-components.umd.js",
58
+
59
+ ### 组件文档构建
60
+
61
+ ```
62
+ npm run docs:dev
63
+ npm run docs:build
64
+ 文档部署到Github Pages: npm run docs:deploy
65
+ ```
66
+
67
+ [组件文档·Github Pages](https://heqican.github.io/by-frontend-components-docs/)
68
+
55
69
  ### 关于新组件开发
56
70
 
57
71
  1. 采用 by 为前缀命名方式
package/deploy.sh ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env sh
2
+
3
+ # 脚本作用:将组件文档 部署到GitHub Pages
4
+
5
+ # 确保脚本抛出遇到的错误
6
+ set -e
7
+
8
+ # 生成静态文件
9
+ npm run docs:build
10
+
11
+ # 进入生成的文件夹
12
+ cd docs/.vuepress/dist
13
+
14
+ # 如果是发布到自定义域名
15
+ # echo 'www.example.com' > CNAME
16
+
17
+ git init
18
+ git add -A
19
+ git commit -m 'deploy docs'
20
+
21
+ # 部署到GitHub Pages
22
+ git branch -M gh-pages
23
+ git push -f https://github.com/heqican/by-frontend-components-docs gh-pages
24
+
25
+ cd -
@@ -0,0 +1,338 @@
1
+ # By Components 文档搭建指南
2
+
3
+ 本指南介绍了如何为 Vue2 组件库搭建 VuePress 文档网站的完整过程。
4
+
5
+ ## 📁 文档结构
6
+
7
+ ```
8
+ docs/
9
+ ├── .vuepress/ # VuePress 配置目录
10
+ │ ├── config.js # 主配置文件
11
+ │ ├── enhanceApp.js # 应用增强配置
12
+ │ └── public/ # 静态资源
13
+ │ ├── favicon.ico # 网站图标
14
+ │ └── logo.png # 网站 Logo
15
+ ├── guide/ # 指南文档
16
+ │ ├── README.md # 指南首页
17
+ │ ├── installation.md # 安装指南
18
+ │ └── quick-start.md # 快速上手
19
+ ├── components/ # 组件文档
20
+ │ ├── README.md # 组件总览
21
+ │ ├── form.md # 表单组件
22
+ │ ├── table.md # 表格组件
23
+ │ ├── pager.md # 分页组件
24
+ │ ├── page-search.md # 页面搜索组件
25
+ │ ├── fold-search.md # 折叠搜索组件
26
+ │ ├── select.md # 选择器组件
27
+ │ └── date-picker-range.md # 日期范围选择器
28
+ └── README.md # 文档首页
29
+ ```
30
+
31
+ ## 🚀 快速开始
32
+
33
+ ### 1. 安装依赖
34
+
35
+ ```bash
36
+ npm install --save-dev vuepress@1.9.10 @vuepress/plugin-back-to-top @vuepress/plugin-medium-zoom
37
+ ```
38
+
39
+ ### 2. 添加构建脚本
40
+
41
+ 在 `package.json` 中添加:
42
+
43
+ ```json
44
+ {
45
+ "scripts": {
46
+ "docs:dev": "vuepress dev docs",
47
+ "docs:build": "vuepress build docs"
48
+ }
49
+ }
50
+ ```
51
+
52
+ ### 3. 启动开发服务器
53
+
54
+ ```bash
55
+ npm run docs:dev
56
+ ```
57
+
58
+ ### 4. 构建生产版本
59
+
60
+ ```bash
61
+ npm run docs:build
62
+ ```
63
+
64
+ ## ⚙️ 配置说明
65
+
66
+ ### VuePress 配置 (docs/.vuepress/config.js)
67
+
68
+ ```javascript
69
+ const path = require('path')
70
+
71
+ module.exports = {
72
+ title: 'By Components',
73
+ description: '基于 Vue2 + Element UI 的业务组件库',
74
+ base: '/',
75
+
76
+ themeConfig: {
77
+ nav: [
78
+ { text: '指南', link: '/guide/' },
79
+ { text: '组件', link: '/components/' }
80
+ ],
81
+ sidebar: {
82
+ '/guide/': [
83
+ /* 指南侧边栏 */
84
+ ],
85
+ '/components/': [
86
+ /* 组件侧边栏 */
87
+ ]
88
+ }
89
+ },
90
+
91
+ plugins: ['@vuepress/back-to-top', '@vuepress/medium-zoom']
92
+ }
93
+ ```
94
+
95
+ ### 应用增强配置 (docs/.vuepress/enhanceApp.js)
96
+
97
+ ```javascript
98
+ import Vue from 'vue'
99
+ import ElementUI from 'element-ui'
100
+ import 'element-ui/lib/theme-chalk/index.css'
101
+ import ByComponents from '../../src/index.js'
102
+ import '../../src/style/index.scss'
103
+
104
+ Vue.use(ElementUI)
105
+ Vue.use(ByComponents)
106
+ ```
107
+
108
+ ## 📝 编写文档
109
+
110
+ ### 组件文档模板
111
+
112
+ 每个组件文档应包含以下部分:
113
+
114
+ 1. **组件介绍** - 简述组件功能和用途
115
+ 2. **基础用法** - 展示最简单的使用方式
116
+ 3. **高级用法** - 展示复杂场景的使用方式
117
+ 4. **API 文档** - 详细的属性、事件、方法说明
118
+
119
+ ### 示例代码
120
+
121
+ ```markdown
122
+ # 组件名称
123
+
124
+ 组件简介...
125
+
126
+ ## 基础用法
127
+
128
+ <template>
129
+ <component-name :prop="value" @event="handler" />
130
+ </template>
131
+
132
+ <script>
133
+ export default {
134
+ data() {
135
+ return {
136
+ value: 'example'
137
+ }
138
+ },
139
+ methods: {
140
+ handler() {
141
+ // 处理逻辑
142
+ }
143
+ }
144
+ }
145
+ </script>
146
+
147
+ ## API
148
+
149
+ ### Props
150
+
151
+ | 参数 | 说明 | 类型 | 默认值 |
152
+ | ---- | -------- | ------ | ------ |
153
+ | prop | 属性说明 | string | '' |
154
+
155
+ ### Events
156
+
157
+ | 事件名 | 说明 | 参数 |
158
+ | ------ | -------- | ------- |
159
+ | event | 事件说明 | (value) |
160
+ ```
161
+
162
+ ## 🎨 主题定制
163
+
164
+ ### 自定义样式
165
+
166
+ 可以在 `docs/.vuepress/styles/` 目录下添加自定义样式:
167
+
168
+ ```
169
+ docs/.vuepress/styles/
170
+ ├── index.styl # 全局样式
171
+ ├── palette.styl # 主题色彩配置
172
+ └── override.styl # 样式覆盖
173
+ ```
174
+
175
+ ### 主题色彩配置
176
+
177
+ ```stylus
178
+ // docs/.vuepress/styles/palette.styl
179
+ $accentColor = #3eaf7c
180
+ $textColor = #2c3e50
181
+ $borderColor = #eaecef
182
+ $codeBgColor = #282c34
183
+ ```
184
+
185
+ ## 🔧 常用插件
186
+
187
+ ### 推荐插件列表
188
+
189
+ ```bash
190
+ # 返回顶部
191
+ npm install @vuepress/plugin-back-to-top
192
+
193
+ # 图片缩放
194
+ npm install @vuepress/plugin-medium-zoom
195
+
196
+ # 代码复制
197
+ npm install vuepress-plugin-copy-code
198
+
199
+ # 全文搜索
200
+ npm install @vuepress/plugin-search
201
+
202
+ # Google Analytics
203
+ npm install @vuepress/plugin-google-analytics
204
+ ```
205
+
206
+ ### 插件配置
207
+
208
+ ```javascript
209
+ module.exports = {
210
+ plugins: [
211
+ '@vuepress/back-to-top',
212
+ '@vuepress/medium-zoom',
213
+ [
214
+ 'copy-code',
215
+ {
216
+ copySelector: ['div[class*="language-"] pre', 'div[class*="aside-code"] aside']
217
+ }
218
+ ],
219
+ [
220
+ '@vuepress/search',
221
+ {
222
+ searchMaxSuggestions: 10
223
+ }
224
+ ]
225
+ ]
226
+ }
227
+ ```
228
+
229
+ ## 🚀 部署
230
+
231
+ ### GitHub Pages
232
+
233
+ 1. 配置 `base` 路径:
234
+
235
+ ```javascript
236
+ module.exports = {
237
+ base: '/your-repo-name/'
238
+ // ...
239
+ }
240
+ ```
241
+
242
+ 2. 创建部署脚本:
243
+
244
+ ```bash
245
+ #!/usr/bin/env sh
246
+
247
+ # 确保脚本抛出遇到的错误
248
+ set -e
249
+
250
+ # 生成静态文件
251
+ npm run docs:build
252
+
253
+ # 进入生成的文件夹
254
+ cd docs/.vuepress/dist
255
+
256
+ git init
257
+ git add -A
258
+ git commit -m 'deploy'
259
+
260
+ # 推送到 gh-pages 分支
261
+ git push -f git@github.com:username/repo.git master:gh-pages
262
+
263
+ cd -
264
+ ```
265
+
266
+ ### Netlify
267
+
268
+ 1. 连接 GitHub 仓库
269
+ 2. 设置构建命令:`npm run docs:build`
270
+ 3. 设置发布目录:`docs/.vuepress/dist`
271
+
272
+ ## 📊 性能优化
273
+
274
+ ### 1. 代码分割
275
+
276
+ ```javascript
277
+ // 异步加载组件示例
278
+ const ComponentDemo = () => import('./components/ComponentDemo.vue')
279
+ ```
280
+
281
+ ### 2. 图片优化
282
+
283
+ - 使用 WebP 格式
284
+ - 添加图片懒加载
285
+ - 压缩图片资源
286
+
287
+ ### 3. 构建优化
288
+
289
+ ```javascript
290
+ module.exports = {
291
+ chainWebpack: (config, isServer) => {
292
+ // 优化构建配置
293
+ config.optimization.splitChunks({
294
+ chunks: 'all'
295
+ })
296
+ }
297
+ }
298
+ ```
299
+
300
+ ## 🛠️ 维护指南
301
+
302
+ ### 更新组件文档
303
+
304
+ 1. 当添加新组件时,在 `docs/components/` 目录下创建对应的 `.md` 文件
305
+ 2. 在 `docs/.vuepress/config.js` 的 `sidebar` 配置中添加新页面
306
+ 3. 更新组件总览页面 `docs/components/README.md`
307
+
308
+ ### 版本管理
309
+
310
+ - 使用语义化版本控制
311
+ - 维护 CHANGELOG.md
312
+ - 及时更新文档内容
313
+
314
+ ### 内容审查
315
+
316
+ - 定期检查文档的准确性
317
+ - 确保示例代码可以正常运行
318
+ - 保持文档风格一致
319
+
320
+ ## 📚 参考资源
321
+
322
+ - [VuePress 官方文档](https://vuepress.vuejs.org/)
323
+ - [Element UI 官方文档](https://element.eleme.cn/)
324
+ - [Markdown 语法指南](https://www.markdownguide.org/)
325
+ - [Vue.js 官方文档](https://cn.vuejs.org/)
326
+
327
+ ---
328
+
329
+ ## 🎉 完成!
330
+
331
+ 恭喜你已经成功搭建了 Vue2 组件库的文档网站!现在你可以:
332
+
333
+ 1. ✅ 访问 http://localhost:8080 查看文档
334
+ 2. ✅ 编写和更新组件文档
335
+ 3. ✅ 自定义主题和样式
336
+ 4. ✅ 部署到生产环境
337
+
338
+ 如有问题,请参考上述配置或查阅官方文档。