2024-07-31 17:04:12 +08:00
|
|
|
import { defineConfig, loadEnv, UserConfigExport } from 'vite'
|
2024-07-22 11:11:43 +08:00
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
import * as path from "path";
|
2024-07-31 17:04:12 +08:00
|
|
|
import { resolve } from 'path';
|
2024-07-22 11:11:43 +08:00
|
|
|
import Components from 'unplugin-vue-components/vite';
|
2024-07-31 17:04:12 +08:00
|
|
|
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
|
|
|
|
import { visualizer } from 'rollup-plugin-visualizer'
|
2024-07-22 11:11:43 +08:00
|
|
|
// @ts-ignore
|
2024-07-31 17:04:12 +08:00
|
|
|
import { name, version, description, appName } from "./package.json";
|
2024-07-22 11:11:43 +08:00
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
|
|
|
const __APP_INFO__ = {
|
|
|
|
name: name,
|
|
|
|
appName: appName,
|
|
|
|
version: version,
|
|
|
|
description: description,
|
|
|
|
lastBuildTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
|
|
|
}
|
|
|
|
|
|
|
|
const pathSrc = path.resolve(__dirname, 'src');
|
|
|
|
|
|
|
|
// https://vitejs.dev/config/
|
2024-07-31 17:04:12 +08:00
|
|
|
export default ({ mode }): UserConfigExport => {
|
2024-07-22 11:11:43 +08:00
|
|
|
const env: Record<string, string> = loadEnv(mode, process.cwd(), '')
|
|
|
|
return defineConfig({
|
|
|
|
define: {
|
|
|
|
__APP_ENV: JSON.stringify(env),
|
2024-08-05 16:43:08 +08:00
|
|
|
__APP_INFO: __APP_INFO__,
|
|
|
|
// $: 'jquery',
|
|
|
|
// jQuery: 'jquery'
|
2024-07-22 11:11:43 +08:00
|
|
|
},
|
|
|
|
base: './',
|
|
|
|
plugins: [
|
|
|
|
vue(),
|
|
|
|
vueJsx(),
|
|
|
|
Components({
|
2024-07-31 17:04:12 +08:00
|
|
|
resolvers: [AntDesignVueResolver({ importStyle: false })]
|
2024-07-22 11:11:43 +08:00
|
|
|
}),
|
|
|
|
visualizer({
|
|
|
|
emitFile: false,
|
|
|
|
filename: 'analyze.html',
|
|
|
|
open: false
|
|
|
|
})
|
|
|
|
],
|
|
|
|
server: {
|
|
|
|
host: '0.0.0.0',
|
|
|
|
port: env['VITE_APP_PORT'] as unknown as number,
|
|
|
|
open: false,
|
|
|
|
proxy: {
|
|
|
|
[env["VITE_APP_BASE_API"]]: {
|
|
|
|
target: env["VITE_APP_PROXY_URL"],
|
|
|
|
changeOrigin: true,
|
|
|
|
secure: false,
|
|
|
|
rewrite: path => path.replace(RegExp(`^${env['VITE_APP_BASE_API']}`), '')
|
|
|
|
},
|
|
|
|
[env["VITE_APP_WS_API"]]: {
|
|
|
|
target: env["VITE_APP_WS_PROXY_URL"],
|
|
|
|
ws: true,
|
|
|
|
changeOrigin: true,
|
|
|
|
rewrite: path => path.replace(RegExp(`^${env['VITE_APP_WS_API']}`), ''),
|
|
|
|
}
|
2024-07-31 17:04:12 +08:00
|
|
|
},
|
2024-08-05 16:43:08 +08:00
|
|
|
|
2024-07-22 11:11:43 +08:00
|
|
|
},
|
|
|
|
build: {
|
|
|
|
outDir: 'dist',
|
|
|
|
target: 'modules',
|
|
|
|
chunkSizeWarningLimit: 1500,
|
|
|
|
minify: 'terser',
|
|
|
|
terserOptions: {
|
|
|
|
compress: {
|
|
|
|
//生产环境时移除console
|
|
|
|
// drop_console: env['VITE_DROP_CONSOLE'] as unknown as boolean,
|
|
|
|
// drop_debugger: env['VITE_DROP_CONSOLE'] as unknown as boolean,
|
|
|
|
},
|
|
|
|
format: {
|
|
|
|
//删除注释
|
|
|
|
comments: false
|
|
|
|
}
|
|
|
|
},
|
2024-07-31 17:04:12 +08:00
|
|
|
|
2024-07-22 11:11:43 +08:00
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
|
|
|
manualChunks(id) {
|
|
|
|
if (id.includes('node_modules')) {
|
|
|
|
return id
|
|
|
|
.toString()
|
|
|
|
.split('node_modules/')[1]
|
|
|
|
.split('/')[0]
|
|
|
|
.toString();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
chunkFileNames(chunkInfo) {
|
|
|
|
const facadeModuleId = chunkInfo.facadeModuleId ? chunkInfo.facadeModuleId.split('/') : [];
|
|
|
|
const fileName =
|
|
|
|
facadeModuleId[facadeModuleId.length - 2] || '[name]';
|
|
|
|
return `js/${fileName}/[name].[hash].js`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'@': pathSrc,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
css: {
|
|
|
|
preprocessorOptions: {
|
|
|
|
scss: {
|
|
|
|
charset: false,
|
|
|
|
// 全局css变量
|
|
|
|
additionalData: `
|
|
|
|
@import "@/assets/scss/variable.scss";
|
|
|
|
@import "@/assets/scss/mixin.scss";
|
|
|
|
`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|