vite.config.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import topLevelAwait from 'vite-plugin-top-level-await'
  4. import { resolve } from 'path'
  5. import viteCompression from 'vite-plugin-compression';//Gzip
  6. import { visualizer } from "rollup-plugin-visualizer";
  7. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' // 【svg-icons相关】
  8. import VitePluginHtmlEnv from 'vite-plugin-html-env'
  9. import postcsspxtoviewport from 'postcss-px-to-viewport'
  10. const time = new Date().getTime()
  11. export default defineConfig({
  12. define: {
  13. 'process.env': process.env
  14. },
  15. plugins: [
  16. vue(),
  17. viteCompression(),
  18. VitePluginHtmlEnv(),
  19. visualizer(),
  20. createSvgIconsPlugin({
  21. // 指定需要缓存的图标文件夹
  22. iconDirs: [resolve(process.cwd(), 'src/assets/svg')],
  23. // 指定symbolId格式
  24. symbolId: 'icon-[dir]-[name]',
  25. // svgoOptions: {
  26. // plugins: [
  27. // {
  28. // name: 'removeAttrs',
  29. // params: {
  30. // attrs: ['class', 'data-name', 'fill', 'stroke']
  31. // }
  32. // }
  33. // ]
  34. // }
  35. }),
  36. topLevelAwait({
  37. promiseExportName: '__tla',
  38. promiseImportName: i => `__tla_${i}`
  39. })
  40. ],
  41. base: '/sww/',
  42. resolve: {
  43. alias: {
  44. '@': resolve(__dirname, 'src'),
  45. },
  46. },
  47. server: {
  48. port: 6699,
  49. host: '0.0.0.0',
  50. open: true,
  51. strictPort: false,
  52. proxy: {
  53. '/sww-api': {
  54. target: 'http://192.168.242.21:9099/',
  55. changeOrigin: true,
  56. rewrite: (path) => {
  57. return path.replace(/^\/sww-api/, '')
  58. // return path
  59. }
  60. },
  61. '/ws-api': {
  62. // target: 'ws://8.130.72.63:18073/',
  63. target: 'ws://192.168.242.21:9099/',
  64. ws: true,
  65. changeOrigin: true,
  66. rewrite: path => {
  67. return path.replace(/^\/ws-api/, '')
  68. }
  69. },
  70. '/EzServer6-api': {
  71. target: 'http://74.10.28.116:8090/', // 地图底图代理
  72. changeOrigin: true,
  73. rewrite: path => {
  74. return path
  75. }
  76. },
  77. '/geoserver-api': {
  78. target: 'http://192.168.242.21:9090/', // 地图服务代理
  79. changeOrigin: true,
  80. rewrite: path => {
  81. return path.replace(/^\/geoserver-api/, '')
  82. }
  83. },
  84. '/rh-ws-api': {
  85. target: 'http://74.10.28.28:6990/', // fk
  86. ws: true,
  87. changeOrigin: true,
  88. rewrite: path => {
  89. return path.replace(/^\/rh-ws-api/, '')
  90. }
  91. },
  92. '/history-track-ws-api': {
  93. target: 'http://74.10.28.24:9999/', // fk
  94. ws: true,
  95. changeOrigin: true,
  96. rewrite: path => {
  97. return path.replace(/^\/history-track-ws-api/, '')
  98. }
  99. },
  100. }
  101. },
  102. css: {
  103. preprocessorOptions: {
  104. scss: {
  105. api: "modern-compiler" // or 'modern'
  106. }
  107. },
  108. postcss: {
  109. plugins: [
  110. postcsspxtoviewport({
  111. unitToConvert: 'px',
  112. viewportWidth: 1920,
  113. unitPrecision: 5, // 单位转换后保留的精度
  114. propList: ['*'], // 能转化为vw的属性列表
  115. viewportUnit: 'vw', // 希望使用的视口单位
  116. fontViewportUnit: 'vw', // 字体使用的视口单位
  117. selectorBlackList: ['ignore-'], // 需要忽略的CSS选择器,不会转为视口单位,使用原有的px等单位。
  118. minPixelValue: 1, // 设置最小的转换数值,如果为1的话,只有大于1的值会被转换
  119. mediaQuery: true, // 媒体查询里的单位是否需要转换单位
  120. replace: true, // 是否直接更换属性值,而不添加备用属性
  121. exclude: [], // 忽略某些文件夹下的文件或特定文件,例如 'node_modules' 下的文件
  122. include: [], // 如果设置了include,那将只有匹配到的文件才会被转换
  123. landscape: false, // 是否添加根据 landscapeWidth 生成的媒体查询条件 @media (orientation: landscape)
  124. landscapeUnit: 'vw', // 横屏时使用的单位
  125. landscapeWidth: 1628, // 横屏时使用的视口宽度
  126. }),
  127. ]
  128. }
  129. },
  130. build: {
  131. outDir: "sea-warning-web",
  132. rollupOptions: {//分包优化
  133. output: {
  134. manualChunks(id) {
  135. if (id.includes('node_modules')) {
  136. return time + id.toString().split('node_modules/')[1].split('/')[0].toString();
  137. } else {
  138. return time + id.toString();
  139. }
  140. }
  141. }
  142. }
  143. },
  144. publicDir: 'src/out',
  145. optimizeDeps: {
  146. include: []
  147. }
  148. } as any)