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