import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import topLevelAwait from 'vite-plugin-top-level-await' import { resolve } from 'path' import viteCompression from 'vite-plugin-compression';//Gzip import { visualizer } from "rollup-plugin-visualizer"; import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' // 【svg-icons相关】 import VitePluginHtmlEnv from 'vite-plugin-html-env' const time = new Date().getTime() export default defineConfig({ define: { 'process.env': process.env }, plugins: [ vue(), viteCompression(), VitePluginHtmlEnv(), visualizer(), createSvgIconsPlugin({ // 指定需要缓存的图标文件夹 iconDirs: [resolve(process.cwd(), 'src/assets/svg')], // 指定symbolId格式 symbolId: 'icon-[dir]-[name]', // svgoOptions: { // plugins: [ // { // name: 'removeAttrs', // params: { // attrs: ['class', 'data-name', 'fill', 'stroke'] // } // } // ] // } }), topLevelAwait({ promiseExportName: '__tla', promiseImportName: i => `__tla_${i}` }) ], base: '/', resolve: { alias: { '@': resolve(__dirname, 'src'), '~@': resolve(__dirname, 'src'), '@views': resolve(__dirname, 'src/views'), '@components': resolve(__dirname, 'src/components') }, }, server: { port: 8090, // open: true, https: false, host: '0.0.0.0', strictPort: false, proxy: { '/mock-api': { target: 'https://www.fastmock.site/mock/002bd20e30dcef8f255675f80a50382c/mock', changeOrigin: true, rewrite: path => { return path.replace(/^\/mock-api/, '') } }, } }, build: { outDir: "tszwfw-mobile", rollupOptions: {//分包优化 output: { manualChunks(id) { if (id.includes('node_modules')) { return time + id.toString().split('node_modules/')[1].split('/')[0].toString(); } else { return time + id.toString(); } } } } }, publicDir: 'src/out', optimizeDeps: { include: [] } })