vite.config.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { UserConfig, ConfigEnv, loadEnv, defineConfig } from 'vite';
  2. import postcssPxToViewport8Plugin from 'postcss-px-to-viewport-8-plugin';
  3. import createPlugins from './vite/plugins';
  4. import path from 'path';
  5. export default defineConfig(({ mode, command }: ConfigEnv): UserConfig => {
  6. const env = loadEnv(mode, process.cwd());
  7. return {
  8. // 部署生产环境和开发环境下的URL。
  9. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  10. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  11. base: './',
  12. resolve: {
  13. alias: {
  14. '~': path.resolve(__dirname, './'),
  15. '@': path.resolve(__dirname, './src')
  16. },
  17. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  18. },
  19. // https://cn.vitejs.dev/config/#resolve-extensions
  20. plugins: createPlugins(env, command === 'build'),
  21. server: {
  22. host: '0.0.0.0',
  23. port: 8050,
  24. open: true,
  25. cors: true,
  26. proxy: {
  27. [env.VITE_APP_BASE_API]: {
  28. target: env.VITE_APP_BASE_API,
  29. //target: 'http://localhost:8086/',
  30. changeOrigin: true,
  31. ws: true,
  32. rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
  33. },
  34. '/api': {
  35. // 代理请求之后的请求地址(你的真实接口地址)
  36. target: 'https://cimweb.zjw.sh.cegn.cn:2007/data-business-prod/',
  37. //target: 'http://localhost:9250/',
  38. secure: false,
  39. // 跨域
  40. changeOrigin: true,
  41. rewrite: (path) => path.replace(/^\/api/, '')
  42. },
  43. '/projectapi': {
  44. // 代理请求之后的请求地址(你的真实接口地址)
  45. target: 'https://cimweb.zjw.sh.cegn.cn:2007/data-business-prod-2/',
  46. //target: 'http://localhost:9250/',
  47. secure: false,
  48. // 跨域
  49. changeOrigin: true,
  50. rewrite: (path) => path.replace(/^\/projectapi/, '')
  51. },
  52. '/openapi': {
  53. // 代理请求之后的请求地址(你的真实接口地址)
  54. target: 'https://cimweb.zjw.sh.cegn.cn:2008/',
  55. //target: 'http://localhost:9250/',
  56. secure: false,
  57. // 跨域
  58. changeOrigin: true,
  59. rewrite: (path) => path.replace(/^\/openapi/, '')
  60. },
  61. }
  62. },
  63. css: {
  64. preprocessorOptions: {
  65. scss: {
  66. additionalData: '@import "./src/styles/variables.scss";',
  67. javascriptEnabled: true
  68. }
  69. },
  70. postcss: {
  71. plugins: [
  72. {
  73. postcssPlugin: 'internal:charset-removal',
  74. AtRule: {
  75. charset: (atRule) => {
  76. if (atRule.name === 'charset') {
  77. atRule.remove();
  78. }
  79. }
  80. }
  81. },
  82. postcssPxToViewport8Plugin({
  83. unitToConvert: 'px',
  84. viewportWidth: 1080,
  85. unitPrecision: 6,
  86. propList: ['*'],
  87. viewportUnit: 'vh',
  88. fontViewportUnit: 'vh',
  89. selectorBlackList: [],
  90. minPixelValue: 1,
  91. mediaQuery: true,
  92. replace: true,
  93. exclude: [/node_modules\/(?!element-plus)/, /views\/dataAssetsManage\/dataClean\/antv6/],
  94. landscape: false
  95. }) as any
  96. ]
  97. }
  98. },
  99. // 预编译
  100. optimizeDeps: {
  101. include: [
  102. 'vue',
  103. 'vue-router',
  104. 'pinia',
  105. 'axios',
  106. '@vueuse/core',
  107. 'echarts',
  108. 'vue-i18n',
  109. '@vueup/vue-quill',
  110. 'bpmn-js/lib/Viewer',
  111. 'bpmn-js/lib/Modeler.js',
  112. 'bpmn-js-properties-panel',
  113. 'min-dash',
  114. 'diagram-js/lib/navigation/movecanvas',
  115. 'diagram-js/lib/navigation/zoomscroll',
  116. 'bpmn-js/lib/features/palette/PaletteProvider',
  117. 'bpmn-js/lib/features/context-pad/ContextPadProvider',
  118. 'diagram-js/lib/draw/BaseRenderer',
  119. 'tiny-svg',
  120. 'image-conversion',
  121. 'element-plus/es/components/**/css'
  122. ]
  123. }
  124. };
  125. });