123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- /*
- * @Author: fxs bjnsfxs@163.com
- * @Date: 2024-08-20 14:06:49
- * @LastEditors: fxs bjnsfxs@163.com
- * @LastEditTime: 2024-09-13 16:43:31
- * @FilePath: \Game-Backstage-Management-System\vite.config.ts
- * @Description:
- *
- */
- import { defineConfig } from 'vite'
- import vue from '@vitejs/plugin-vue'
- import { fileURLToPath, URL } from 'node:url'
- import AutoImport from 'unplugin-auto-import/vite'
- import Components from 'unplugin-vue-components/vite'
- import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
- import Icons from 'unplugin-icons/vite'
- import IconsResolver from 'unplugin-icons/resolver'
- import { visualizer } from 'rollup-plugin-visualizer'
- // 打包
- import viteCompression from 'vite-plugin-compression'
- import { ViteImageOptimizer } from 'vite-plugin-image-optimizer'
- const DEFAULT_OPTIONS = {
- test: /\.(jpe?g|png|gif|tiff|webp|svg|avif)$/i,
- includePublic: true,
- logStats: true,
- ansiColors: true,
- svg: {
- multipass: true,
- plugins: [
- {
- name: 'preset-default',
- params: {
- overrides: {
- cleanupNumericValues: false,
- removeViewBox: false // https://github.com/svg/svgo/issues/1128
- },
- cleanupIDs: {
- minify: false,
- remove: false
- },
- convertPathData: false
- }
- },
- 'sortAttrs',
- {
- name: 'addAttributesToSVGElement',
- params: {
- attributes: [{ xmlns: 'http://www.w3.org/2000/svg' }]
- }
- }
- ]
- },
- png: {
- // https://sharp.pixelplumbing.com/api-output#png
- quality: 100
- },
- jpeg: {
- // https://sharp.pixelplumbing.com/api-output#jpeg
- quality: 100
- },
- jpg: {
- // https://sharp.pixelplumbing.com/api-output#jpeg
- quality: 100
- },
- tiff: {
- // https://sharp.pixelplumbing.com/api-output#tiff
- quality: 100
- },
- // gif does not support lossless compression
- // https://sharp.pixelplumbing.com/api-output#gif
- gif: {},
- webp: {
- // https://sharp.pixelplumbing.com/api-output#webp
- lossless: true
- },
- avif: {
- // https://sharp.pixelplumbing.com/api-output#avif
- lossless: true
- },
- cache: false,
- cacheLocation: undefined
- }
- export default defineConfig(({ mode }) => {
- return {
- build: {
- rollupOptions: {
- output: {
- manualChunks: {
- echarts: ['echarts']
- },
- chunkFileNames: 'js/[name]-[hash].js', // 引入文件名的名称
- entryFileNames: 'js/[name]-[hash].js', // 包的入口文件名称
- assetFileNames: '[ext]/[name]-[hash].[ext]' // 资源文件像 字体,图片等
- }
- }
- },
- esbuild: {
- drop: mode === 'production' ? ['console', 'debugger'] : []
- },
- plugins: [
- vue(),
- ViteImageOptimizer(DEFAULT_OPTIONS),
- viteCompression({
- verbose: true, // 默认即可
- disable: false, // 开启压缩(不禁用),默认即可
- deleteOriginFile: false, // 删除源文件
- threshold: 5120, // 压缩前最小文件大小
- algorithm: 'gzip', // 压缩算法
- ext: '.gz' // 文件类型
- }),
- visualizer({ open: true }),
- AutoImport({
- resolvers: [ElementPlusResolver()]
- }),
- Components({
- resolvers: [
- ElementPlusResolver(),
- IconsResolver({
- prefix: 'icon'
- })
- ]
- }),
- Icons({
- autoInstall: true
- })
- ],
- resolve: {
- alias: {
- '@': fileURLToPath(new URL('./src', import.meta.url))
- }
- }
- }
- })
|