-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into main
- Loading branch information
Showing
4 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# 自动导入 | ||
|
||
|
||
## 说明 | ||
在之前的 `2.x` 以及更古老的版本。 | ||
|
||
在使用 `Vue API` 的时候,都需要在文件内写入 `import { ref, ... } from 'vue'` 等等语句。 | ||
现在 `vite` 经过发展,社区的插件已经非常丰富,基于此,我们可以简化代码,提高开发效率,感谢那些大神提供的插件。 | ||
|
||
::: tip 说明 | ||
现在在开发 `*.vue、*.ts、*.tsx` 时,不需要手动引入以下 `API` 或者组件: | ||
|
||
- Vue的所有api | ||
- VueRouter | ||
- Pinia | ||
- 所有的 `store` 文件:`./src/store/modules/*` | ||
- hooks下自动导入目录:`./src/hooks/auto-imports/*` | ||
- 以及 `./src/components/` 下的所有组件 `(只有 *.vue 类型文件可以不显性写导入)` | ||
::: | ||
|
||
## 自定义自动导入 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# 请求与拦截器 | ||
|
||
## 网络请求 | ||
|
||
系统内提供了 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
# 构建与预览 | ||
# 构建与预览 | ||
|
||
## 构建(打包) | ||
项目开发完成之后,要部署在服务器上,则需要对前端项目进行构建打包。 | ||
|
||
执行 `pnpm run build` 命令进行构建,打包成功之后,会在 `./web` 下目录生成 `dist` 文件夹,里面就是打包好的静态文件。 | ||
|
||
::: info 提示 | ||
如果访问地址并未为域名的根节点,如 `https://www.example.com/app` | ||
则需要在 `环境变量文件` 中修改 `VITE_APP_ROOT_BASE` 选项为 `/app`,否则会出现资源引用错误。 | ||
::: | ||
|
||
## 预览 | ||
|
||
为了保证构建打包出来的项目能正常运行,一般需要本地测试一下。 | ||
|
||
这时候可以执行 `pnpm run serve` 命令预览打包好的项目,并以真实的情况访问后端服务器。 | ||
|
||
## 压缩 | ||
|
||
在 `环境变量文件` 里设置 `VITE_BUILD_COMPRESS` 即可在构建打包时生成 .gz 或 .br 文件。但两者均需要 `nginx` 安装指定模块并开启后才会生效。 | ||
```yaml | ||
# 单独开启 gzip | ||
VITE_BUILD_COMPRESS = gzip | ||
|
||
# 单独开启 brotli ,brotli 是比 gzip 压缩率更高的算法 | ||
VITE_BUILD_COMPRESS = brotli | ||
|
||
# 或者也可以都开启,两者可以共存 | ||
VITE_BUILD_COMPRESS = gzip,brotli | ||
``` |