-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
144 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# baseUrl | ||
VITE_BASE_API = '/' | ||
VITE_BASE_API = "/" | ||
|
||
# 线上环境平台打包路径 | ||
VITE_PUBLIC_PATH = / | ||
VITE_PUBLIC_PATH = "/" | ||
|
||
# 生产环境是否启用 cdn | ||
VITE_CDN_DEPS = "false" |
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,12 @@ | ||
import { cdn } from "vite-plugin-cdn2"; | ||
|
||
export function enableCDN(isEnabled: string) { | ||
if (isEnabled === "true") { | ||
return cdn({ | ||
// url 可以更换为私有或其他源 | ||
// url: "https://cdn.jsdelivr.net/npm/", | ||
url: "https://unpkg.com/", | ||
modules: ["vue", "vue-demi", "pinia", "axios", "vant", "vue-router"] | ||
}); | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
93bbe72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
想请教一下这个常量的值类型改为 Boolean:
这样会不会更好些?
93bbe72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
环境变量中直接读到的值都为 String,其他值类型需要做额外的转换处理
93bbe72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你说的没错,我的示例下面判断不成立
既然默认都是String,再加引号是不是更严谨?
看到一些项目的环境变量几乎不加引号
例如
https://github.com/vbenjs/vue-vben-admin/blob/main/.env.production
93bbe72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我提的另外一个疑惑是:
项目里两个环境变量的写法似乎并不统一:有些加了引号,有些并没加引号
93bbe72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其实加不加引号都一样,读出来是字符串。为了更直观知道是字符串,我手动加的而已。。像有些项目里后期做了环境变量值转换的话你上面的判断才能成立 https://github.com/pure-admin/vue-pure-admin/blob/main/build/utils.ts#L45
93bbe72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢答疑
93bbe72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请教下,VITE_CDN_DEPS改为true后,打包会报错vite-plugin-cdn2: vue-demi can't find module,有遇到过这个问题么
93bbe72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不会,启用 cdn 打包后包含了 vue-demi 依赖
93bbe72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
项目中没有直接安装vue-demi,但是pinia用到了,所以需要在引入pinia前引入vue-demi(https://github.com/vuejs/pinia/blob/v2/packages/pinia/package.json#L77)
93bbe72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢回复,项目中是有modules: ["vue", "vue-demi", "pinia", "axios", "vant", "vue-router"]引入的,请问下是还需要安装vue-demi的依赖包,然后在项目中引入吗,方便给下示例么
93bbe72
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要安装 vue-demi,项目 cdn 打包并不会有缺少依赖的报错,需要提供下你代码的 playground 看看