@@ -90,23 +90,29 @@ export default defineConfig(({ command, mode }) => {
90
90
export default defineConfig (async ({ command, mode }) => {
91
91
const data = await asyncFunction ()
92
92
return {
93
- // 构建模式所需的特有配置
93
+ // vite 配置
94
94
}
95
95
})
96
96
```
97
97
98
- ### Environment Variables {#environment-variables}
98
+ ### 环境变量 {#environment-variables}
99
99
100
- Vite 默认是不加载 ` .env ` 文件的,因为这些文件需要在执行完 Vite 配置后才能确定加载哪一个,举个例子,` root ` 和 ` envDir ` 选项会影响加载行为。不过当你的确需要时,你可以使用 Vite 导出的 ` loadEnv ` 函数来加载指定的 ` .env ` 文件
100
+ 环境变量通常可以从 ` process.env ` 获得。
101
+
102
+ 注意 Vite 默认是不加载 ` .env ` 文件的,因为这些文件需要在执行完 Vite 配置后才能确定加载哪一个,举个例子,` root ` 和 ` envDir ` 选项会影响加载行为。不过当你的确需要时,你可以使用 Vite 导出的 ` loadEnv ` 函数来加载指定的 ` .env ` 文件
101
103
102
104
``` js
103
105
import { defineConfig , loadEnv } from ' vite'
104
106
105
107
export default defineConfig (({ command, mode }) => {
106
108
// 根据当前工作目录中的 `mode` 加载 .env 文件
107
- const env = loadEnv (mode, process .cwd ())
109
+ // 设置第三个参数为 '' 来加载所有环境变量,而不管是否有 `VITE_` 前缀。
110
+ const env = loadEnv (mode, process .cwd (), ' ' )
108
111
return {
109
- // 构建特定配置
112
+ // vite config
113
+ define: {
114
+ __APP_ENV__ : env .APP_ENV
115
+ }
110
116
}
111
117
})
112
118
```
@@ -298,7 +304,11 @@ export default defineConfig(({ command, mode }) => {
298
304
299
305
- ** 类型:** ` string | (postcss.ProcessOptions & { plugins?: postcss.Plugin[] }) `
300
306
301
- 内联的 PostCSS 配置(格式同 ` postcss.config.js ` ),或者一个(默认基于项目根目录的)自定义的 PostCSS 配置路径。其路径搜索是通过 [ postcss-load-config] ( https://github.com/postcss/postcss-load-config ) 实现的,并且只加载支持的配置文件名称。
307
+ 内联的 PostCSS 配置(格式同 ` postcss.config.js ` ),或者一个(默认基于项目根目录的)自定义的 PostCSS 配置路径。
308
+
309
+ 对内联的 POSTCSS 配置,它期望接收与 ` postcss.config.js ` 一致的格式。但对于 ` plugins ` 属性有些特别,只接收使用 [ 数组格式] ( https://github.com/postcss/postcss-load-config/blob/main/README.md#array ) 。
310
+
311
+ 搜索是使用 [ postcss-load-config] ( https://github.com/postcss/postcss-load-config ) 完成的,只有被支持的文件名才会被加载。
302
312
303
313
注意:如果提供了该内联配置,Vite 将不会搜索其他 PostCSS 配置源。
304
314
@@ -694,7 +704,7 @@ createServer()
694
704
``` js
695
705
export default defineConfig ({
696
706
server: {
697
- origin: ' http://127.0.0.1:8080/ '
707
+ origin: ' http://127.0.0.1:8080'
698
708
}
699
709
})
700
710
```
0 commit comments