zhzf/client/vite.config.js

93 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vitePluginCompression from 'vite-plugin-compression'
import path from 'path'
// https://vite.dev/config/
export default defineConfig(({ mode, command }) => {
// 加载环境变量
const env = loadEnv(mode, process.cwd())
return {
// 服务器配置
server: {
host: '0.0.0.0',
port: 5173,
open: false,
proxy: {
'/api': {
target: 'http://localhost:9091',
changeOrigin: true,
},
'/lawenforcement': {
target: 'http://localhost:9091',
changeOrigin: true,
},
'/rest': {
target: 'http://222.91.125.86:8090',
changeOrigin: true,
},
'/pangu': {
target: 'http://222.91.125.86:8090',
changeOrigin: true,
},
'/dah-login': {
target: 'http://10.22.245.227:1084',
changeOrigin: true,
},
'/dah-api': {
target: 'http://10.22.245.227:1084',
changeOrigin: true,
},
},
},
publicDir: path.resolve(__dirname, 'public'),
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'@pages': path.resolve(__dirname, 'src/views'),
'@views': path.resolve(__dirname, 'src/views'),
'@css': path.resolve(__dirname, 'src/styles'),
},
},
plugins: [
vue(),
vitePluginCompression({
// 可以指定压缩的文件类型,例如只压缩图片文件
include: /\.(png|jpg|jpeg|gif|svg)$/i,
// 压缩算法选项如gzip、brotli等这里以gzip为例
algorithm: 'gzip',
// 压缩阈值,只有文件大小大于此值时才进行压缩
threshold: 1024,
}),
],
css: {
preprocessorOptions: {
scss: {
prependData: `@import "./src/styles/variables.scss";`,
},
},
},
build: {
outDir: path.resolve(__dirname, `dist`), // 指定输出路径
assetsInlineLimit: 4096, //小于此阈值的导入或引用资源将内联为 base64 编码,以避免额外的 http 请求
emptyOutDir: true, //Vite 会在构建时清空该目录
rollupOptions: {
input: {
main: path.resolve(__dirname, 'index.html'),
},
},
output: {
assetFileNames: '[ext]/[name]-[hash].[ext]',
chunkFileNames: 'js/[name]-[hash].js',
entryFileNames: 'js/[name]-[hash].js',
compact: true,
manualChunks: (id) => {
if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[0].toString() // 拆分多个vendors
}
},
},
},
}
})