import { resolve } from 'path'; import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import vueJsx from '@vitejs/plugin-vue-jsx'; import { vitePluginCommonjs } from 'vite-plugin-commonjs'; import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'; import eslint from 'vite-plugin-eslint'; import VueSetupExtend from 'vite-plugin-vue-setup-extend'; // eslint-disable-next-line import/no-unresolved import AutoImport from 'unplugin-auto-import/vite'; import { visualizer } from 'rollup-plugin-visualizer'; import viteCompression from 'vite-plugin-compression'; import { createHtmlPlugin } from 'vite-plugin-html'; import { name } from './package.json'; export default defineConfig(({ command, mode }) => { // 本地代理 const proxy = { '/apictis': { // target: 'https://saictl.szairport.com', // prod // target: 'http://192.168.40.136:7002', // test target: 'http://172.16.46.110:7002', // dev // target: 'http://192.168.40.106:7002', // tb // target: 'http://192.168.40.125:7002', // lqw changeOrigin: true, rewrite: (path) => path.replace(/^\/apictis/, ''), }, }; const plugins = [ viteCompression(), createHtmlPlugin({ minify: true, inject: { data: { title: name, }, }, }), vue({ reactivityTransform: true, }), vueJsx(), vitePluginCommonjs(), // VueSetupExtend(), AutoImport({ // 可以自定义文件生成的位置,默认是根目录下,使用ts的建议放src目录下 dts: 'src/auto-imports.d.ts', imports: ['vue'], // 解决eslint报错问题 eslintrc: { enabled: true, }, }), createSvgIconsPlugin({ // 指定需要缓存的图标文件夹 iconDirs: [resolve(process.cwd(), 'src/icons')], // 指定symbolId格式 symbolId: 'icon-[dir]-[name]', }), eslint({ include: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.vue'], exclude: ['node_modules'], }), ]; if (process.env.report) { plugins.push( visualizer({ open: true, brotliSize: true, filename: 'report.html' }) ); } return { base: './', server: { proxy, }, build: { reportCompressedSize: false, rollupOptions: { output: { manualChunks: { echarts: ['echarts', 'vue-echarts'], i18n: ['vue-i18n'], arcoDesign: ['@arco-design/web-vue'], dayjs: ['dayjs'], }, }, }, }, plugins, resolve: { alias: [ { find: '@', replacement: resolve(__dirname, 'src'), }, ], extensions: ['.ts', '.js'], }, css: { preprocessorOptions: { less: { modifyVars: { // 'arcoblue-6': '#1b1b1b', }, javascriptEnabled: true, }, }, }, define: { 'process.env': {}, }, test: {}, }; });