vite.config.mjs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { defineConfig } from 'vite';
  2. // 移动端rem适配相关
  3. import pxtorem from "postcss-pxtorem";
  4. import vue from '@vitejs/plugin-vue';
  5. import legacy from '@vitejs/plugin-legacy' // 用于生成传统浏览器兼容版本
  6. import viteCompression from 'vite-plugin-compression'
  7. // https://vitejs.dev/config/
  8. export default defineConfig(({ mode }) => {
  9. return {
  10. base:'./',
  11. cacheDir: false,
  12. /**
  13. * 项目根目录
  14. * @see https://cn.vite.dev/config/shared-options.html#root
  15. */
  16. root: './src',
  17. /**
  18. * 静态资源目录,相对于 src/index.html 文件
  19. * @see https://cn.vite.dev/config/shared-options.html#publicdir
  20. */
  21. publicDir: '../public',
  22. server: {
  23. port: 5173,
  24. host: '0.0.0.0', // IP配置,支持从IP启动
  25. proxy: {
  26. '/iaserverapi': {
  27. // target: 'http://192.168.141.78:5678',
  28. // target: 'http://192.168.0.101:5678',
  29. // target: 'http://25.214.216.111:9000',
  30. target: 'http://47.117.92.63:5678/',
  31. // target: 'http://172.20.10.2:5678',
  32. changeOrigin: true,
  33. secure: false,
  34. ws: true,
  35. // cors: true,
  36. // rewrite: (path) => path.replace(/^\/proxy_url/, '/iaserverapi')
  37. },
  38. }
  39. },
  40. build: {
  41. /**
  42. * 构建输出目录,相对于 src/index.html 文件
  43. * @see https://cn.vite.dev/config/build-options.html#build-outdir
  44. */
  45. outDir: '../dist',
  46. emptyOutDir: true,
  47. // target: 'es2015',
  48. // minify: 'terser', // 使用 terser 进行更彻底的转换
  49. rollupOptions: {
  50. output: {
  51. // // 确保生成的资源路径使用相对路径
  52. assetFileNames: 'assets/thrid-nrpw-pwai-[name].[ext]',
  53. chunkFileNames: 'assets/thrid-nrpw-pwai-[name].[hash].js',
  54. entryFileNames: 'assets/thrid-nrpw-pwai-[name].[hash].js',
  55. manualChunks: {
  56. 'vue-vendor': ['vue', 'vue-router']
  57. },
  58. }
  59. },
  60. terserOptions: {
  61. output: {
  62. // 去掉注释内容
  63. comments: true,
  64. // drop_console: true, // 移除console
  65. }
  66. },
  67. },
  68. plugins: [
  69. vue(),
  70. // legacy({
  71. // targets: ['defaults', 'not IE 11','chrome < 60'], // 如果你需要兼容 IE11,可调整此配置
  72. // additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
  73. // renderLegacyChunks:true,
  74. // polyfills: ['es.promise.all-settled','es.symbol','es.promise','es.promise.finally','es/map','es/set','es.array.filter'] // 明确包含 allSettled 的 polyfill
  75. // }),
  76. ],
  77. css:{
  78. postcss: {
  79. plugins: [
  80. pxtorem({
  81. rootValue: 37.5,
  82. propList: ['*'],
  83. selectorBlackList: ['van-']
  84. })
  85. ]
  86. }
  87. }
  88. };
  89. });