vite.config.ts 3.5 KB

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