import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import { createSvgIconsPlugin } from "vite-plugin-svg-icons"
import svgLoader from "vite-svg-loader"
import UnoCSS from "unocss/vite"
const resolve = (dir) => path.join(__dirname, dir)
export default defineConfig(({ mode }) => {
const config = loadEnv(mode, './')
return {
base: './',
build: {
chunkSizeWarningLimit: 2000,
minify: "terser",
terserOptions: {
compress: {
drop_console: false,
drop_debugger: true,
pure_funcs: ["console.log"]
},
format: {
comments: false
}
},
assetsDir: "static",
rollupOptions: {
output: {
assetFileNames: assetInfo => {
var info = assetInfo.name.split('.')
var extType = info[info.length - 1]
if (
/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i.test(assetInfo.name)
) {
extType = 'media'
} else if (/\.(png|jpe?g|gif|svg)(\?.*)?$/.test(assetInfo.name)) {
extType = 'img'
} else if (/\.(woff2?|eot|ttf|otf)(\?.*)?$/i.test(assetInfo.name)) {
extType = 'fonts'
}
return `static/${extType}/[name]-[hash][extname]`
},
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js'
}
},
},
plugins: [
vue(),
svgLoader(),
createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), "src/icons/svg")],
symbolId: "icon-[dir]-[name]"
}),
UnoCSS()
],
resolve: {
alias: {
'@': resolve('src'),
comps: resolve('src/components'),
apis: resolve('src/apis'),
views: resolve('src/views'),
utils: resolve('src/utils'),
routes: resolve('src/routes'),
styles: resolve('src/styles')
}
},
server: {
https: false,
host: true,
port: 3333,
open: false,
cors: true,
strictPort: false,
proxy: {
'/basice': {
target: config.VITE_BASIC_URL,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/basice/, '')
}
}
},
}
})