88 lines
2.2 KiB
TypeScript
88 lines
2.2 KiB
TypeScript
import { UserConfig } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
|
|
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
|
import viteCompression from 'vite-plugin-compression'
|
|
import DefineOptions from 'unplugin-vue-define-options/vite';
|
|
|
|
import path from 'path'
|
|
|
|
const viteConfig: UserConfig = {
|
|
plugins: [
|
|
vue(),
|
|
DefineOptions(),
|
|
createSvgIconsPlugin({
|
|
// 指定要缓存的文件夹
|
|
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons/svg')],
|
|
// 指定symbolId格式
|
|
symbolId: '[name]'
|
|
}),
|
|
AutoImport({
|
|
resolvers: [ElementPlusResolver()],
|
|
}),
|
|
Components({
|
|
dirs: ['./src/components'],
|
|
extensions: ['vue'],
|
|
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
|
|
resolvers: [ElementPlusResolver({
|
|
importStyle: 'sass'
|
|
})]
|
|
}),
|
|
viteCompression({
|
|
verbose: true,
|
|
disable: false,
|
|
threshold: 10240,
|
|
algorithm: 'gzip',
|
|
ext: '.gz'
|
|
})
|
|
],
|
|
base: './',
|
|
resolve: {
|
|
alias: {
|
|
"/@": "/src"
|
|
}
|
|
},
|
|
server: {
|
|
port: 7791,
|
|
open: true,
|
|
host: '0.0.0.0',
|
|
proxy: {
|
|
'/api': {
|
|
target: 'http://127.0.0.1:7788/', //开发服务器地址
|
|
changeOrigin: true,
|
|
rewrite: (path) => path.replace(/^\/api/, ''),
|
|
},
|
|
},
|
|
},
|
|
assetsInclude: path.resolve(__dirname, 'src/assets'),
|
|
build: {
|
|
outDir: 'deploy/dist',
|
|
minify: 'esbuild',
|
|
sourcemap: false,
|
|
chunkSizeWarningLimit: 1500,
|
|
rollupOptions: {
|
|
output: {
|
|
entryFileNames: `assets/[name].${new Date().getTime()}.js`,
|
|
chunkFileNames: `assets/[name].${new Date().getTime()}.js`,
|
|
assetFileNames: `assets/[name].${new Date().getTime()}.[ext]`,
|
|
manualChunks(id) {
|
|
// 静态资源拆分
|
|
if (id.includes("node_modules")) {
|
|
return id
|
|
.toString()
|
|
.split("node_modules/")[1]
|
|
.split("/")[0]
|
|
.toString();
|
|
}
|
|
},
|
|
}
|
|
},
|
|
},
|
|
};
|
|
|
|
export default viteConfig;
|