2024-08-29 17:06:00 +08:00
|
|
|
import {defineConfig, loadEnv} from 'vite'
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
import Components from 'unplugin-vue-components/vite';
|
|
|
|
import {AntDesignVueResolver} from 'unplugin-vue-components/resolvers';
|
|
|
|
import * as path from "node:path";
|
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
2024-11-21 10:12:05 +08:00
|
|
|
import {appName, version, name as moduleName} from './package.json'
|
2024-08-29 17:06:00 +08:00
|
|
|
|
|
|
|
const pathSrc = path.resolve(__dirname, 'src');
|
|
|
|
|
|
|
|
// https://vitejs.dev/config/
|
|
|
|
export default defineConfig(({mode}) => {
|
|
|
|
const env: Record<string, string> = loadEnv(mode, process.cwd(), '')
|
|
|
|
return {
|
|
|
|
define: {
|
2024-11-21 10:06:30 +08:00
|
|
|
__APP_ENV: JSON.stringify(env),
|
|
|
|
__APP_INFO: JSON.stringify({
|
2024-11-21 10:12:05 +08:00
|
|
|
moduleName,
|
2024-11-21 10:06:30 +08:00
|
|
|
appName,
|
|
|
|
version
|
|
|
|
})
|
2024-08-29 17:06:00 +08:00
|
|
|
},
|
2024-11-21 10:12:05 +08:00
|
|
|
base: `/${moduleName}/`,
|
2024-08-29 17:06:00 +08:00
|
|
|
plugins: [
|
|
|
|
vue(),
|
|
|
|
vueJsx(),
|
|
|
|
Components({
|
|
|
|
resolvers: [
|
|
|
|
AntDesignVueResolver({importStyle: false})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'@': pathSrc,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
server: {
|
|
|
|
host: '0.0.0.0',
|
|
|
|
port: parseInt(env['VITE_APP_PORT']),
|
|
|
|
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']}`), '')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
build: {
|
2024-11-21 10:12:05 +08:00
|
|
|
outDir: moduleName,
|
2024-08-29 17:06:00 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2024-11-13 09:31:37 +08:00
|
|
|
css: {
|
|
|
|
preprocessorOptions: {
|
|
|
|
api: 'modern-compiler'
|
|
|
|
}
|
|
|
|
}
|
2024-08-29 17:06:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
})
|