96 lines
2.4 KiB
TypeScript
96 lines
2.4 KiB
TypeScript
import { resolve } from 'path';
|
|
import { defineConfig } from 'vite';
|
|
import vue from '@vitejs/plugin-vue';
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
import svgLoader from 'vite-svg-loader';
|
|
import configArcoStyleImportPlugin from './plugin/arcoStyleImport';
|
|
|
|
export default defineConfig({
|
|
plugins: [
|
|
vue(),
|
|
vueJsx(),
|
|
svgLoader({ svgoConfig: {} }),
|
|
configArcoStyleImportPlugin(),
|
|
],
|
|
resolve: {
|
|
alias: [
|
|
{
|
|
find: '@',
|
|
replacement: resolve(__dirname, '../src'),
|
|
},
|
|
{
|
|
find: 'assets',
|
|
replacement: resolve(__dirname, '../src/assets'),
|
|
},
|
|
{
|
|
find: 'vue-i18n',
|
|
replacement: 'vue-i18n/dist/vue-i18n.cjs.js', // Resolve the i18n warning issue
|
|
},
|
|
{
|
|
find: 'vue',
|
|
replacement: 'vue/dist/vue.esm-bundler.js', // compile template
|
|
},
|
|
],
|
|
extensions: ['.ts', '.js'],
|
|
},
|
|
define: {
|
|
'process.env': {},
|
|
},
|
|
build: {
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks: {
|
|
// 核心框架
|
|
vendor: ['vue', 'vue-router', 'pinia'],
|
|
// UI 框架
|
|
arco: ['@arco-design/web-vue'],
|
|
// 工具库
|
|
utils: ['lodash', 'dayjs', 'axios'],
|
|
// 图表库
|
|
charts: ['echarts', 'vue-echarts'],
|
|
// 持久化插件
|
|
persist: ['pinia-plugin-persistedstate'],
|
|
},
|
|
// 优化 chunk 命名
|
|
chunkFileNames: (chunkInfo) => {
|
|
if (chunkInfo.name) {
|
|
return `js/[name]-[hash].js`;
|
|
}
|
|
return `js/chunk-[hash].js`;
|
|
},
|
|
// 优化入口文件命名
|
|
entryFileNames: 'js/[name]-[hash].js',
|
|
// 优化资源文件命名
|
|
assetFileNames: (assetInfo) => {
|
|
if (assetInfo.name?.endsWith('.css')) {
|
|
return 'css/[name]-[hash].css';
|
|
}
|
|
return 'assets/[name]-[hash].[ext]';
|
|
},
|
|
},
|
|
},
|
|
chunkSizeWarningLimit: 1000,
|
|
// 压缩选项
|
|
minify: 'terser',
|
|
terserOptions: {
|
|
compress: {
|
|
// 移除 console 和 debugger
|
|
drop_console: true,
|
|
drop_debugger: true,
|
|
},
|
|
},
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
less: {
|
|
modifyVars: {
|
|
hack: `true; @import (reference) "${resolve(
|
|
'src/assets/style/breakpoint.less'
|
|
)}";`,
|
|
},
|
|
javascriptEnabled: true,
|
|
},
|
|
},
|
|
},
|
|
});
|