|
| 1 | +--- |
| 2 | +title: 0 VChart 工程化 |
| 3 | + |
| 4 | +key words: VisActor,VChart,VTable,VStrory,VMind,VGrammar,VRender,Visualization,Chart,Data,Table,Graph,Gis,LLM |
| 5 | +--- |
| 6 | +# 0.1 启动 demo |
| 7 | + |
| 8 | +## 0.1.1 Fork 项目 |
| 9 | + |
| 10 | +在 Github 上,你需要 Fork VChart 项目。 |
| 11 | + |
| 12 | +<img src='https://cdn.jsdelivr.net/gh/xuanhun/articles/visactor/sourcecode/img/XgFMbjw62o7QnDxfi62cfY6znKe.gif' alt='' width='1000' height='auto' /> |
| 13 | + |
| 14 | +## 0.1.2 克隆项目 |
| 15 | + |
| 16 | +在你 fork 的仓库中,点击 `Code` 按钮,复制项目地址。然后使用 git clone 命令克隆项目到本地。例如: |
| 17 | + |
| 18 | +```bash |
| 19 | +git clone https://github.com/your-username/VChart.git |
| 20 | + |
| 21 | +``` |
| 22 | +克隆完毕后需要添加 VChart 的远程地址。 |
| 23 | + |
| 24 | +```bash |
| 25 | +git remote add upstream https://github.com/VisActor/VChart.git |
| 26 | + |
| 27 | +``` |
| 28 | +这样以后你就可以从 VChart 的远程地址获取最新的源码。 |
| 29 | + |
| 30 | +```bash |
| 31 | +git pull upstream develop |
| 32 | + |
| 33 | +``` |
| 34 | +## 0.1.3 启动 demo |
| 35 | + |
| 36 | +我们是用 [@microsoft/rush](https://rushjs.io/) 来管理 monorepo。所以先安装 rush。 |
| 37 | + |
| 38 | +```bash |
| 39 | +npm install -g @microsoft/rush |
| 40 | + |
| 41 | +``` |
| 42 | +接下来执行命令启动 demo。 |
| 43 | + |
| 44 | +```typescript |
| 45 | +*安装依赖* |
| 46 | +$ rush update |
| 47 | +*启动 vchart 的demo页* |
| 48 | +$ rush start |
| 49 | +*启动 react-vchart 的demo页* |
| 50 | +$ rush react |
| 51 | +*启动本地文档站点* |
| 52 | +$ rush docs |
| 53 | + |
| 54 | +``` |
| 55 | +## 0.1.4 启动 demo 的时候发生了什么? |
| 56 | + |
| 57 | +当你运行 `rush start` 的时候,会启动 vchart 的 demo 页。可是具体发生了什么呢? |
| 58 | + |
| 59 | +首先我们在 `command-line.json` 中配置了 `start` 命令: |
| 60 | + |
| 61 | +```json |
| 62 | +{"commandKind": "global","name": "start","summary": "Start the development server","description": "Run this command to start vchart development server","shellCommand": "rush run -p @visactor/vchart -s start"}, |
| 63 | + |
| 64 | +``` |
| 65 | +所以我们得知 start 命令会执行 `rush run -p @visactor/vchart -s start` 命令。 |
| 66 | + |
| 67 | +让我详细解释 `rush run -p @visactor/vchart -s start` 这个命令: |
| 68 | + |
| 69 | +这是一个 Rush 工具的命令,可以拆解为以下几个部分: |
| 70 | + |
| 71 | +1. `rush run`:Rush 的子命令,用于在 monorepo 中运行特定项目的 npm 脚本 |
| 72 | + |
| 73 | +1. `-p @visactor/vchart`:`-p` 或 `--project` 参数,指定要运行脚本的项目名称,这里指定的是 @visactor/vchart 项目 |
| 74 | + |
| 75 | +1. `-s start`:`-s` 或 `--script` 参数,指定要运行的 npm 脚本名称,这里要运行的是 start 脚本 |
| 76 | + |
| 77 | +根据代码库,我们可以看到这个命令最终会执行 @visactor/vchart 包中 package.json 定义的 start 脚本: |
| 78 | + |
| 79 | +```bash |
| 80 | +ts-node __tests__/runtime/browser/scripts/initVite.ts && vite serve __tests__/runtime/browser |
| 81 | + |
| 82 | +``` |
| 83 | +这个命令前半部分是运行初始化脚本 `initVite.ts`,它的主要作用是生成 local 版本的 `vite.config.local.ts` 和 `index.page.local.ts` 文件,这两个文件是被 git 忽略的,用于本地开发的配置,后面会详细讲到。 |
| 84 | + |
| 85 | +后半部分的脚本 `vite serve __tests__/runtime/browser`是启动 demo 网页。 |
| 86 | + |
| 87 | +## 0.1.5 如何使用 `index.page.local.ts` |
| 88 | + |
| 89 | +该文件的默认内容为 |
| 90 | + |
| 91 | +```xml |
| 92 | +import './test-page/area'; |
| 93 | + |
| 94 | +``` |
| 95 | +笼统的来说,它可以用来指定启动不同的 chart 页面。实际上它就是会运行不同文件的 VChart 表格生成代码,来达到网页启动不同的 chart 页面的效果。所以你只要 import 不同的文件,就可以启动不同的 chart 页面。 |
| 96 | + |
| 97 | +## 0.1.6 如何使用 `vite.config.local.ts` |
| 98 | + |
| 99 | +这个文件主要用来配置端口和本地包。比如下面的配置: |
| 100 | + |
| 101 | +```xml |
| 102 | +export default { |
| 103 | + *// 启动端口*port: 4000, |
| 104 | + resolve: { |
| 105 | + alias: { |
| 106 | + '@visactor/vgrammar-core': '/path/to/visactor/VGrammar/packages/vgrammar-core/src/index.ts', |
| 107 | + '@visactor/vgrammar-util': '/path/to/visactor/VGrammar/packages/vgrammar-util/src/index.ts', |
| 108 | + '@visactor/vgrammar-wordcloud': '/path/to/visactor/VGrammar/packages/vgrammar-wordcloud/src/index.ts', |
| 109 | + '@visactor/vgrammar-wordcloud-shape': '/path/to/visactor/VGrammar/packages/vgrammar-wordcloud-shape/src/index.ts', |
| 110 | + '@visactor/vgrammar-sankey': '/path/to/visactor/VGrammar/packages/vgrammar-sankey/src/index.ts', |
| 111 | + '@visactor/vgrammar-hierarchy': '/path/to/visactor/VGrammar/packages/vgrammar-hierarchy/src/index.ts', |
| 112 | + '@visactor/vgrammar-projection': '/path/to/visactor/VGrammar/packages/vgrammar-projection/src/index.ts', |
| 113 | + '@visactor/vgrammar-coordinate': '/path/to/visactor/VGrammar/packages/vgrammar-coordinate/src/index.ts', |
| 114 | + '@visactor/vgrammar-venn': '/path/to/visactor/VGrammar/packages/vgrammar-venn/src/index.ts', |
| 115 | + '@visactor/vscale': '/path/to/visactor/VUtil/packages/vscale/src/index.ts', |
| 116 | + '@visactor/vdataset': '/path/to/visactor/VUtil/packages/vdataset/src/index.ts', |
| 117 | + '@visactor/vutils': '/path/to/visactor/VUtil/packages/vutils/src/index.ts', |
| 118 | + '@visactor/vrender-core': '/path/to/visactor/VRender/packages/vrender-core/src/index.ts', |
| 119 | + '@visactor/vrender-kits': '/path/to/visactor/VRender/packages/vrender-kits/src/index.ts', |
| 120 | + '@visactor/vrender-components': '/path/to/visactor/VRender/packages/vrender-components/src/index.ts' |
| 121 | + } |
| 122 | + } |
| 123 | +}; |
| 124 | + |
| 125 | +``` |
| 126 | +它把启动端口配置为 4000,并且配置了一系列的本地包,这样你的 VChart 在调试时会依赖这些本地包,你对上游本地包的改动会实时生效,方便调试一些和上游有关的 bug,如果你不需要这个功能,去掉这些配置即可。 |
| 127 | + |
| 128 | +# 0.2 VChart 工程化详解 |
| 129 | + |
| 130 | +## 0.2.1 项目结构 |
| 131 | + |
| 132 | +VChart 是一个使用 Rush 管理的 monorepo 项目,主要包含以下几个部分: |
| 133 | + |
| 134 | +核心包: |
| 135 | + |
| 136 | +1. @visactor/vchart - 核心图表库 |
| 137 | + |
| 138 | +1. @visactor/react-vchart - React 封装 |
| 139 | + |
| 140 | +1. @visactor/openinula-vchart - OpenInula 封装 |
| 141 | + |
| 142 | +1. @visactor/taro-vchart - Taro 封装 |
| 143 | + |
| 144 | +1. @visactor/lark-vchart - 飞书封装 |
| 145 | + |
| 146 | +1. @visactor/wx-vchart - 微信小程序封装 |
| 147 | + |
| 148 | +1. @visactor/vchart-schema - 图表配置 Schema |
| 149 | + |
| 150 | +1. @visactor/vchart-types - TypeScript 类型定义 |
| 151 | + |
| 152 | +1. @visactor/vutils-extension - 工具函数扩展 |
| 153 | + |
| 154 | +1. @visactor/tt-vchart - 字节小程序封装 |
| 155 | + |
| 156 | +工具包: |
| 157 | + |
| 158 | +1. @internal/bundler - 打包工具 |
| 159 | + |
| 160 | +1. @internal/typescript-json-schema - TypeScript 类型定义生成工具 |
| 161 | + |
| 162 | +1. @internal/story-player - 故事播放器 |
| 163 | + |
| 164 | +1. @internal/bugserver-trigger - Bug 服务触发器 |
| 165 | + |
| 166 | +## 0.2.2 文档系统 |
| 167 | + |
| 168 | +文档的内容都存储在 `docs/assets` 文件夹下,比如包含: |
| 169 | + |
| 170 | +* API 文档 |
| 171 | + |
| 172 | +* 示例代码 |
| 173 | + |
| 174 | +* 教程文档 |
| 175 | + |
| 176 | +* 配置项文档 |
| 177 | + |
| 178 | +* 主题文档 |
| 179 | + |
| 180 | +## 0.2.3 开发命令 |
| 181 | + |
| 182 | +* rush update - 安装依赖 |
| 183 | + |
| 184 | +* rush start - 启动 vchart 开发服务 |
| 185 | + |
| 186 | +* rush react - 启动 react-vchart 开发服务 |
| 187 | + |
| 188 | +* rush docs - 启动文档开发服务 |
| 189 | + |
| 190 | + |
| 191 | + |
| 192 | + # 本文档由以下人员修正整理 |
| 193 | + [玄魂](https://github.com/xuanhun) |
0 commit comments