Skip to content

Commit a447aad

Browse files
docs: add explanation and related script configuration to distinguish build environment
1 parent a0222fd commit a447aad

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

docs/src/en/guide/essentials/development.md

+67
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,73 @@ To run the `docs` application:
150150
pnpm dev:docs
151151
```
152152

153+
### Distinguishing Build Environments
154+
155+
In actual business development, multiple environments are usually distinguished during the build process, such as the test environment `test` and the production environment `build`.
156+
157+
At this point, you can modify three files and add corresponding script configurations to distinguish between production environments.
158+
159+
Take the addition of the test environment `test` to `@vben/web-antd` as an example:
160+
161+
- `apps\web-antd\package.json`
162+
163+
```json
164+
"scripts": {
165+
"build:prod": "pnpm vite build --mode production",
166+
"build:test": "pnpm vite build --mode test",
167+
"build:analyze": "pnpm vite build --mode analyze",
168+
"dev": "pnpm vite --mode development",
169+
"preview": "vite preview",
170+
"typecheck": "vue-tsc --noEmit --skipLibCheck"
171+
}
172+
```
173+
174+
Add the command `"build:test"` and change the original `"build"` to `"build:prod"` to avoid building packages for two environments simultaneously.
175+
176+
- `package.json`
177+
178+
```json
179+
"scripts": {
180+
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 turbo build",
181+
"build:analyze": "turbo build:analyze",
182+
"build:antd": "pnpm run build --filter=@vben/web-antd",
183+
"build-test:antd": "pnpm run build --filter=@vben/web-antd build:test",
184+
185+
······
186+
}
187+
```
188+
189+
Add the command to build the test environment in the root directory `package.json`.
190+
191+
- `turbo.json`
192+
193+
```json
194+
"tasks": {
195+
"build": {
196+
"dependsOn": ["^build"],
197+
"outputs": [
198+
"dist/**",
199+
"dist.zip",
200+
".vitepress/dist.zip",
201+
".vitepress/dist/**"
202+
]
203+
},
204+
205+
"build-test:antd": {
206+
"dependsOn": ["@vben/web-antd#build:test"],
207+
"outputs": ["dist/**"]
208+
},
209+
210+
"@vben/web-antd#build:test": {
211+
"dependsOn": ["^build"],
212+
"outputs": ["dist/**"]
213+
},
214+
215+
······
216+
```
217+
218+
Add the relevant dependent commands in `turbo.json`.
219+
153220
## Public Static Resources
154221

155222
If you need to use public static resources in the project, such as images, static HTML, etc., and you want to directly import them in the development process through `src="/xxx.png"`.

docs/src/guide/essentials/development.md

+67
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,73 @@ pnpm dev:ele
150150
pnpm dev:docs
151151
```
152152

153+
## 区分构建环境
154+
155+
在实际的业务开发种,通常会在构建时区分多种环境,如测试环境`test`、生产环境`build`等。
156+
157+
此时可以修改三个文件,在其中增加对应的脚本配置来达到区分生产环境的效果。
158+
159+
`@vben/web-antd`添加测试环境`test`为例:
160+
161+
- `apps\web-antd\package.json`
162+
163+
```json
164+
"scripts": {
165+
"build:prod": "pnpm vite build --mode production",
166+
"build:test": "pnpm vite build --mode test",
167+
"build:analyze": "pnpm vite build --mode analyze",
168+
"dev": "pnpm vite --mode development",
169+
"preview": "vite preview",
170+
"typecheck": "vue-tsc --noEmit --skipLibCheck"
171+
},
172+
```
173+
174+
增加命令`"build:test"`, 并将原`"build"`改为`"build:prod"`以避免同时构建两个环境的包。
175+
176+
- `package.json`
177+
178+
```json
179+
"scripts": {
180+
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 turbo build",
181+
"build:analyze": "turbo build:analyze",
182+
"build:antd": "pnpm run build --filter=@vben/web-antd",
183+
"build-test:antd": "pnpm run build --filter=@vben/web-antd build:test",
184+
185+
······
186+
}
187+
```
188+
189+
在根目录`package.json`中加入构建测试环境的命令
190+
191+
- `turbo.json`
192+
193+
```json
194+
"tasks": {
195+
"build": {
196+
"dependsOn": ["^build"],
197+
"outputs": [
198+
"dist/**",
199+
"dist.zip",
200+
".vitepress/dist.zip",
201+
".vitepress/dist/**"
202+
]
203+
},
204+
205+
"build-test:antd": {
206+
"dependsOn": ["@vben/web-antd#build:test"],
207+
"outputs": ["dist/**"]
208+
},
209+
210+
"@vben/web-antd#build:test": {
211+
"dependsOn": ["^build"],
212+
"outputs": ["dist/**"]
213+
},
214+
215+
······
216+
```
217+
218+
在`turbo.json`中加入相关依赖的命令
219+
153220
## 公共静态资源
154221

155222
项目中需要使用到的公共静态资源,如:图片、静态HTML等,需要在开发中通过 `src="/xxx.png"` 直接引入的。

0 commit comments

Comments
 (0)