vite 区分生产环境开发环境
示例 1
vite.config.ts
import { defineConfig, loadEnv } from 'vite'
import { resolve } from 'path'
export default ({ mode }) => {
const __DEV__ = mode === 'development'
return defineConfig({
base: __DEV__ ? '/' : 'emoji-popover',
root: 'example',
server: {
open: false,
port: 3000
},
build: {
outDir: '../docs',
emptyOutDir: true
}
})
}
示例 2
vite.config.ts
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
export default ({ mode }) => {
process.env = {...process.env, ...loadEnv(mode, process.cwd())};
// import.meta.env.VITE_NAME available here with: process.env.VITE_NAME
// import.meta.env.VITE_PORT available here with: process.env.VITE_PORT
return defineConfig({
plugins: [vue()],
server: {
port: process.env.VITE_PORT,
},
});
}