|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import { defineConfig, loadEnv } from 'vite'
- import vue from '@vitejs/plugin-vue'
- import path from 'path'
- //@ts-ignore
- import viteCompression from 'vite-plugin-compression'
-
- // https://vitejs.dev/config/
- export default defineConfig(({ command, mode }) => {
- //https://blog.csdn.net/huanglgln/article/details/121635053 vite获取.env.development配置环境
- // 使用 import.meta.env.VITE_APP_BASE_URL
- loadEnv(mode, process.cwd());
- return {
- base: './', //打包路径
- plugins: [
- vue(),
- // gzip压缩 生产环境生成 .gz 文件
- viteCompression({
- verbose: true,
- disable: false,
- threshold: 10240,
- algorithm: 'gzip',
- ext: '.gz',
- }),
- ],
- // 配置别名
- resolve: {
- alias: {
- '@': path.resolve(__dirname, 'src'),
- },
- },
- define: { //定义 process
- 'process.env': process.env
- },
- css: {
- preprocessorOptions: {
- scss: { //引入全局样式
- additionalData: '@import "@/assets/style/mian.scss";',
- },
- },
- },
- entry: {
- index: ["babel-polyfill", "./src/main.ts"],
- },
- //启动服务配置
- server: {
- host: '0.0.0.0',
- port: 8085,
- open: true, // 类型: boolean | string在服务器启动时自动在浏览器中打开应用程序;
- cors: true, // 类型: boolean | CorsOptions 为开发服务器配置 CORS。默认启用并允许任何源
- https: false,
- proxy: {
- '/api': {
- target: process.env.VUE_APP_BASE_API,
- changeOrigin: true,
- rewrite: path => path.replace(/^\/api/, '') //重写
- },
- '/corporateaccount': {
- target: process.env.VUE_APP_BASE_API,
- changeOrigin: true,
- rewrite: path => path.replace(/^\/api/, '') //重写
- },
- },
- },
- // 生产环境打包配置
- //去除 console debugger
- build: {
- terserOptions: {
- compress: {
- drop_console: true,
- drop_debugger: true,
- },
- },
- },
- }
- })
|