011Vite打包与开发态的常用配置vite.config.ts
Vite指定配置文件vite --config my-config.js
建立配置文件.env.development/.env.production
# 本地开发环境变量
NODE_ENV=development
APP_HTTP_URL=127.0.0.1
APP_HTTP_PORT=909
APP_DIST_DIR=../../web-client-dist/ui/
# 接口地址
APP_API_HTTP=http://127.0.0.1:9098
vite.config.ts配置文件及详细说明如下:
import { fileURLToPath, URL } from 'node:url';
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
export default defineConfig(({ command, mode, ssrBuild }) => {
console.log(666.701, command, mode, ssrBuild);
const IS_PROD = mode === 'production';
const { APP_HTTP_URL, APP_HTTP_PORT, APP_API_HTTP, APP_DIST_DIR } = loadEnv(
mode,
process.cwd(),
''
);
console.log(666.702, APP_HTTP_URL, APP_HTTP_PORT, APP_API_HTTP, APP_DIST_DIR);
return {
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
server: {
host: APP_HTTP_URL,
port: Number(APP_HTTP_PORT),
open: true,
cros: true,
proxy: {
'^/api': {
target: APP_API_HTTP,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
esbuild: {
drop: IS_PROD ? ['debugger', 'console'] : [],
},
build: {
sourcemap: !IS_PROD,
outDir: APP_DIST_DIR,
rollupOptions: {
brotliSize: false,
target: 'esnext',
minify: 'esbuild',
plugins: [
],
},
chunkSizeWarningLimit: 2000,
cssCodeSplit: true,
assetsInlineLimit: 5000,
minify: false,
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
};
});