Newer
Older
DH_Apicture / vite.config.js
@ZZJ ZZJ 15 days ago 4 KB 视频id
  1. import { defineConfig, loadEnv } from 'vite';
  2. import path from 'path';
  3. import createVitePlugins from './vite/plugins';
  4. import postCssPxToRem from 'postcss-pxtorem';
  5. import autoprefixer from 'autoprefixer';
  6.  
  7. const Timestamp = new Date().getTime(); //随机时间戳
  8. let ipLink = 'https://server1.wh-nf.cn:8201/prod-api';
  9. // let ipLink = 'http://192.168.16.135:9100';
  10. // let ipLink = 'https://dhgx.wh-nf.cn:8201/prod-api';
  11. // let ipLink = 'http://192.168.16.124:9100';
  12. // let ipLink = 'http://192.168.20.43:9100'; // 刘总
  13. // let ipLink = 'http://192.168.16.43:9100';
  14.  
  15. /* */
  16. // https://vitejs.dev/config/
  17. export default defineConfig(({ mode, command }) => {
  18. const env = loadEnv(mode, process.cwd());
  19. const { VITE_APP_ENV } = env;
  20. return {
  21. // 部署生产环境和开发环境下的URL。
  22. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  23. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  24. base: VITE_APP_ENV === 'production' ? '/WaterBrain' : '/',
  25. // 是否开启eslint保存检测
  26. lintOnSave: false,
  27. plugins: createVitePlugins(env, command === 'build'),
  28. resolve: {
  29. // https://cn.vitejs.dev/config/#resolve-alias
  30. alias: {
  31. // 设置路径
  32. '~': path.resolve(__dirname, './'),
  33. // 设置别名
  34. '@': path.resolve(__dirname, './src'),
  35. },
  36. // https://cn.vitejs.dev/config/#resolve-extensions
  37. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
  38. },
  39. // vite 相关配置
  40. server: {
  41. port: 8888,
  42. host: true,
  43. hot: true, //自动保存
  44. cors: true,
  45. hmr: true, //vue3 vite配置热更新不用手动刷新
  46. open: true,
  47. proxy: {
  48. '/business': {
  49. target: ipLink,
  50. changeOrigin: true,
  51. rewrite: p => p.replace(/^\/business/, '/business'),
  52. },
  53. '/internetVehicles': {
  54. target: ipLink,
  55. changeOrigin: true,
  56. },
  57. '/system': {
  58. target: ipLink,
  59. changeOrigin: true,
  60. rewrite: p => p.replace(/^\/system/, '/system'),
  61. },
  62. '/auth': {
  63. target: ipLink,
  64. changeOrigin: true,
  65. rewrite: p => p.replace(/^\/auth/, '/auth'),
  66. },
  67. '/code': {
  68. target: ipLink,
  69. changeOrigin: true,
  70. rewrite: p => p.replace(/^\/code/, '/code'),
  71. },
  72. '/prod-api/amap': {
  73. target: 'https://restapi.amap.com', //geocode服务
  74. changeOrigin: true,
  75. rewrite: p => p.replace('/prod-api/amap', ''),
  76. },
  77. '/prod-api/bdApi': {
  78. // target: 'http://192.168.16.34:8105/', //测试服务
  79. target: 'https://server2.wh-nf.cn:8088/prod-api/bdApi/', //测试服务
  80. changeOrigin: true,
  81. logLevel: 'debug',
  82. rewrite: p => p.replace('/prod-api/bdApi', ''),
  83. },
  84. '/prod-api': {
  85. target: ipLink,
  86. changeOrigin: true,
  87. logLevel: 'debug',
  88. rewrite: p => p.replace(/^\/prod-api/, ''),
  89. },
  90. },
  91. },
  92. css: {
  93. postcss: {
  94. plugins: [
  95. {
  96. postcssPlugin: 'internal:charset-removal',
  97. AtRule: {
  98. charset: atRule => {
  99. if (atRule.name === 'charset') {
  100. atRule.remove();
  101. }
  102. },
  103. },
  104. },
  105. postCssPxToRem({
  106. // 自适应,px>rem转换
  107. rootValue: 192, // 根据设计图尺寸写,设计图是 1920,就写 192
  108. propList: ['*'], // 需要转换的属性,这里选择全部都进行转换
  109. selectorBlackList: ['-nopx'], // 过滤掉-nopx结尾的class,不进行rem转换
  110. }),
  111. autoprefixer({
  112. // 自动添加前缀
  113. overrideBrowserslist: [
  114. 'Android 4.1',
  115. 'iOS 7.1',
  116. 'Chrome > 31',
  117. 'ff > 31',
  118. 'ie >= 8',
  119. //'last 2 versions', // 所有主流浏览器最近2个版本
  120. ],
  121. grid: true,
  122. }),
  123. ],
  124. },
  125. },
  126. build: {
  127. sourcemap: false,
  128. outDir: 'WaterBrain',
  129. rollupOptions: {
  130. output: {
  131. chunkFileNames: `static/js/[name].[hash]${Timestamp}.js`,
  132. entryFileNames: `static/js/[name].[hash]${Timestamp}.js`,
  133. assetFileNames: `static/[ext]/[name].[hash]${Timestamp}.[ext]`,
  134. },
  135. brotliSize: true, // 不统计
  136. target: 'esnext',
  137. minify: 'esbuild', // 混淆器,terser构建后文件体积更小
  138. },
  139. },
  140. };
  141. });