import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import path from 'path' import Components from 'unplugin-vue-components/vite'; import { VantResolver } from 'unplugin-vue-components/resolvers'; import DefineOptions from 'unplugin-vue-define-options/vite'; import { visualizer } from 'rollup-plugin-visualizer' // yyhh import legacy from '@vitejs/plugin-legacy'; const isVisualizer = process.env.VISUALIZER === 'show' export default defineConfig({ base: './', plugins: [ vue(), Components({ resolvers: [VantResolver()], }), DefineOptions(), isVisualizer && visualizer({ gzipSize: true }), // yyhh // legacy({ // targets: ['defaults', 'not IE 11'], // }), ], css: { preprocessorOptions: { scss: { additionalData: `@import "@/assets/css/variable.scss";` }, } }, // server: { // open: true, // port: 333, // hmr: true, // host: '0.0.0.0', // proxy: { // "/api": { // target: "http://api.swftek.com", //填写反向代理8085后的域名 // changeOrigin: true, // secure: false // }, // }, // }, server: { open: true, port: 333, host: '0.0.0.0', proxy: { // 关键:用正则表达式匹配所有含/api的路径(忽略大小写) '^/api.*': { // 匹配以/api开头的任何路径(如/api、/api/xxx、/api?xx等) // target: 'http://154.23.189.28:8086', target:'https://api.mak-web3.com', // target:'https://api.mak-web3.com', // target: 'https://by2.cccxxx.cc', changeOrigin: true, secure: false, // logLevel: 'debug', // 打印详细代理日志 rewrite: (path) => path, // 不修改路径(如果目标API本身就有/api前缀) configure: (proxy) => { proxy.on('proxyReq', (proxyReq, req) => { console.log(`[代理成功] 捕获请求: ${req.method} ${req.url}`); }); proxy.on('error', (err) => { console.log(`[代理错误] ${err.message}`); }); } } } }, resolve: { dedupe: [ 'vue' ], alias: { 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js', "~": path.resolve(__dirname, './'), "@": path.resolve(__dirname, 'src'), } }, build: { assetsDir: "static", chunkSizeWarningLimit: 5000, // 改为1000KiB // yyhh target: 'esnext', // 或者 'es2019' / 'es2020' // 明确设置支持异步生成器的目标环境 rollupOptions: { input: { index: path.resolve(__dirname, "index.html"), }, output: { chunkFileNames: 'js/[name]-[hash].js', entryFileNames: "js/[name]-[hash].js", assetFileNames: "[ext]/[name]-[hash].[ext]" }, }, }, externals: ['vue'] })