import { defineConfig } from 'vite'; // 移动端rem适配相关 import pxtorem from "postcss-pxtorem"; import vue from '@vitejs/plugin-vue'; import legacy from '@vitejs/plugin-legacy' // 用于生成传统浏览器兼容版本 import viteCompression from 'vite-plugin-compression' // https://vitejs.dev/config/ export default defineConfig(({ mode }) => { return { base:'./', cacheDir: false, /** * 项目根目录 * @see https://cn.vite.dev/config/shared-options.html#root */ root: './src', /** * 静态资源目录,相对于 src/index.html 文件 * @see https://cn.vite.dev/config/shared-options.html#publicdir */ publicDir: '../public', server: { port: 5173, host: '0.0.0.0', // IP配置,支持从IP启动 proxy: { '/iaserverapi': { // target: 'http://192.168.141.78:5678', // target: 'http://192.168.0.101:5678', // target: 'http://25.214.216.111:9000', target: 'http://47.117.92.63:5678/', // target: 'http://172.20.10.2:5678', changeOrigin: true, secure: false, ws: true, // cors: true, // rewrite: (path) => path.replace(/^\/proxy_url/, '/iaserverapi') }, } }, build: { /** * 构建输出目录,相对于 src/index.html 文件 * @see https://cn.vite.dev/config/build-options.html#build-outdir */ outDir: '../dist', emptyOutDir: true, // target: 'es2015', // minify: 'terser', // 使用 terser 进行更彻底的转换 rollupOptions: { output: { // // 确保生成的资源路径使用相对路径 assetFileNames: 'assets/thrid-nrpw-pwai-[name].[ext]', chunkFileNames: 'assets/thrid-nrpw-pwai-[name].[hash].js', entryFileNames: 'assets/thrid-nrpw-pwai-[name].[hash].js', manualChunks: { 'vue-vendor': ['vue', 'vue-router'] }, } }, terserOptions: { output: { // 去掉注释内容 comments: true, // drop_console: true, // 移除console } }, }, plugins: [ vue(), // legacy({ // targets: ['defaults', 'not IE 11','chrome < 60'], // 如果你需要兼容 IE11,可调整此配置 // additionalLegacyPolyfills: ['regenerator-runtime/runtime'], // renderLegacyChunks:true, // polyfills: ['es.promise.all-settled','es.symbol','es.promise','es.promise.finally','es/map','es/set','es.array.filter'] // 明确包含 allSettled 的 polyfill // }), ], css:{ postcss: { plugins: [ pxtorem({ rootValue: 37.5, propList: ['*'], selectorBlackList: ['van-'] }) ] } } }; });