vite.config.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import monacoEditorPlugin from 'vite-plugin-monaco-editor';
  4. import removeConsole from 'vite-plugin-remove-console';
  5. import compression from 'vite-plugin-compression';
  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. compression(),
  24. monacoEditorPlugin({}), // 启用 Monaco Editor 插件
  25. AutoImport({
  26. //安装两行后你会发现在组件中不用再导入ref,reactive等
  27. imports: ['vue', 'vue-router'],
  28. //存放的位置
  29. dts: "src/auto-import.d.ts",
  30. }),
  31. Components({
  32. // 引入组件的,包括自定义组件,存放的位置
  33. dts: "src/components.d.ts",
  34. }),
  35. VueSetupExtend(),
  36. ],
  37. //1、 ↓解析配置
  38. resolve: {
  39. // ↓路径别名
  40. alias: {
  41. '@': resolve('src'),
  42. '@views': resolve('src/views')
  43. }
  44. },
  45. //代理
  46. server: {
  47. proxy: {
  48. '/api': {
  49. // target: 'http://192.168.0.131:8188/TransServlet',//配置文件获取地址
  50. target: 'https://www.adicn.com/airopt',
  51. secure: false, //接受使用https
  52. changeOrigin: true, //允许跨域
  53. ws: false, //使用websocket
  54. rewrite: (path) => path.replace(/^\/api/, '')
  55. },
  56. '/airopt': {
  57. // target: 'http://192.168.0.131:8188/TransServlet',//配置文件获取地址
  58. target: 'https://www.adicn.com/airopt',
  59. secure: false, //接受使用https
  60. changeOrigin: true, //允许跨域
  61. ws: false, //使用websocket
  62. rewrite: (path) => path.replace(/^\/airopt/, '')
  63. },
  64. '/file': {
  65. // target: 'http://192.168.0.15:8081/', // 后端接口地址
  66. target: 'http://192.168.0.43:2201/',
  67. secure: false, //接受使用https
  68. changeOrigin: true, //允许跨域
  69. ws: false, //使用websocket
  70. pathRewrite: { // 路径重写
  71. '^/file': ''
  72. }
  73. }, '/websokct': {
  74. target: 'http://192.168.0.104:8188',
  75. // target: 'http://192.168.0.43:8081/',
  76. // target: 'https://www.gzchain.org.cn/managersvc/', //后端接口地址
  77. secure: false, //接受使用https
  78. },
  79. }
  80. },
  81. renderer: {
  82. css: {
  83. preprocessorOptions: {
  84. scss: {
  85. silenceDeprecations: ['legacy-js-api']
  86. }
  87. }
  88. }
  89. }
  90. }
  91. })