vite.config.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import monacoEditorPlugin from 'vite-plugin-monaco-editor';
  4. import viteImagemin from 'vite-plugin-imagemin';
  5. import removeConsole from 'vite-plugin-remove-console';
  6. //1、 导入 path 模块,帮助我们解析路径
  7. import { resolve } from 'path'
  8. //2-1 自动导入vue中hook reactive ref等
  9. import AutoImport from 'unplugin-auto-import/vite'
  10. //2-2 自动导入ui-组件 比如说ant-design-vue element-plus等
  11. import Components from 'unplugin-vue-components/vite'
  12. //3、vue3语法糖
  13. import VueSetupExtend from 'vite-plugin-vue-setup-extend'
  14. // https://vitejs.dev/config/
  15. export default defineConfig(({ mode }) => {
  16. const config = loadEnv(mode, './');
  17. console.log(config);
  18. return {
  19. base: "./",
  20. plugins: [
  21. vue(),
  22. removeConsole(),
  23. viteImagemin({
  24. // imagemin 配置项
  25. gifsicle: {
  26. optimizationLevel: 7,
  27. interlaced: false,
  28. },
  29. optipng: {
  30. optimizationLevel: 7,
  31. },
  32. mozjpeg: {
  33. quality: 20,
  34. },
  35. pngquant: {
  36. quality: [0.8, 0.9],
  37. speed: 4,
  38. },
  39. svgo: {
  40. plugins: [
  41. {
  42. name: 'removeViewBox',
  43. active: false,
  44. },
  45. ],
  46. },
  47. }),
  48. monacoEditorPlugin({}), // 启用 Monaco Editor 插件
  49. AutoImport({
  50. //安装两行后你会发现在组件中不用再导入ref,reactive等
  51. imports: ['vue', 'vue-router'],
  52. //存放的位置
  53. dts: "src/auto-import.d.ts",
  54. }),
  55. Components({
  56. // 引入组件的,包括自定义组件,存放的位置
  57. dts: "src/components.d.ts",
  58. }),
  59. VueSetupExtend(),
  60. ],
  61. //1、 ↓解析配置
  62. resolve: {
  63. // ↓路径别名
  64. alias: {
  65. '@': resolve('src'),
  66. '@views': resolve('src/views')
  67. }
  68. },
  69. //代理
  70. server: {
  71. proxy: {
  72. '/api': {
  73. // target: 'http://192.168.0.131:8188/TransServlet',//配置文件获取地址
  74. target: 'https://www.adicn.com/airopt',
  75. secure: false, //接受使用https
  76. changeOrigin: true, //允许跨域
  77. ws: false, //使用websocket
  78. rewrite: (path) => path.replace(/^\/api/, '')
  79. },
  80. '/airopt': {
  81. // target: 'http://192.168.0.131:8188/TransServlet',//配置文件获取地址
  82. target: 'https://www.adicn.com/airopt',
  83. secure: false, //接受使用https
  84. changeOrigin: true, //允许跨域
  85. ws: false, //使用websocket
  86. rewrite: (path) => path.replace(/^\/airopt/, '')
  87. },
  88. '/file': {
  89. // target: 'http://192.168.0.15:8081/', // 后端接口地址
  90. target: 'http://192.168.0.43:2201/',
  91. secure: false, //接受使用https
  92. changeOrigin: true, //允许跨域
  93. ws: false, //使用websocket
  94. pathRewrite: { // 路径重写
  95. '^/file': ''
  96. }
  97. }, '/websokct': {
  98. target: 'http://192.168.0.104:8188',
  99. // target: 'http://192.168.0.43:8081/',
  100. // target: 'https://www.gzchain.org.cn/managersvc/', //后端接口地址
  101. secure: false, //接受使用https
  102. },
  103. }
  104. },
  105. renderer: {
  106. css: {
  107. preprocessorOptions: {
  108. scss: {
  109. silenceDeprecations: ['legacy-js-api']
  110. }
  111. }
  112. }
  113. }
  114. }
  115. })