@@ -90,23 +90,29 @@ export default defineConfig(({ command, mode }) => {
9090export default defineConfig (async ({ command, mode }) => {
9191 const data = await asyncFunction ()
9292 return {
93- // 构建模式所需的特有配置
93+ // vite 配置
9494 }
9595})
9696```
9797
98- ### Environment Variables {#environment-variables}
98+ ### 环境变量 {#environment-variables}
9999
100- Vite 默认是不加载 ` .env ` 文件的,因为这些文件需要在执行完 Vite 配置后才能确定加载哪一个,举个例子,` root ` 和 ` envDir ` 选项会影响加载行为。不过当你的确需要时,你可以使用 Vite 导出的 ` loadEnv ` 函数来加载指定的 ` .env ` 文件
100+ 环境变量通常可以从 ` process.env ` 获得。
101+
102+ 注意 Vite 默认是不加载 ` .env ` 文件的,因为这些文件需要在执行完 Vite 配置后才能确定加载哪一个,举个例子,` root ` 和 ` envDir ` 选项会影响加载行为。不过当你的确需要时,你可以使用 Vite 导出的 ` loadEnv ` 函数来加载指定的 ` .env ` 文件
101103
102104``` js
103105import { defineConfig , loadEnv } from ' vite'
104106
105107export default defineConfig (({ command, mode }) => {
106108 // 根据当前工作目录中的 `mode` 加载 .env 文件
107- const env = loadEnv (mode, process .cwd ())
109+ // 设置第三个参数为 '' 来加载所有环境变量,而不管是否有 `VITE_` 前缀。
110+ const env = loadEnv (mode, process .cwd (), ' ' )
108111 return {
109- // 构建特定配置
112+ // vite config
113+ define: {
114+ __APP_ENV__ : env .APP_ENV
115+ }
110116 }
111117})
112118```
@@ -298,7 +304,11 @@ export default defineConfig(({ command, mode }) => {
298304
299305- ** 类型:** ` string | (postcss.ProcessOptions & { plugins?: postcss.Plugin[] }) `
300306
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 ) 完成的,只有被支持的文件名才会被加载。
302312
303313 注意:如果提供了该内联配置,Vite 将不会搜索其他 PostCSS 配置源。
304314
@@ -694,7 +704,7 @@ createServer()
694704``` js
695705export default defineConfig ({
696706 server: {
697- origin: ' http://127.0.0.1:8080/ '
707+ origin: ' http://127.0.0.1:8080'
698708 }
699709})
700710```
0 commit comments