vite.config.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. import { viteStaticCopy } from 'vite-plugin-static-copy';
  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. viteStaticCopy({
  38. targets: [
  39. {
  40. src: 'node_modules/monaco-editor/min/vs',
  41. dest: 'monaco-editor', // 会变成 dist/monaco-editor/vs
  42. },
  43. ],
  44. }),
  45. ],
  46. //1、 ↓解析配置
  47. resolve: {
  48. // ↓路径别名
  49. alias: {
  50. '@': resolve('src'),
  51. '@views': resolve('src/views')
  52. }
  53. },
  54. //代理
  55. server: {
  56. proxy: {
  57. '/api': {
  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(/^\/api/, '')
  64. },
  65. '/airopt': {
  66. // target: 'http://192.168.0.131:8188/TransServlet',//配置文件获取地址
  67. target: 'https://www.adicn.com/airopt',
  68. secure: false, //接受使用https
  69. changeOrigin: true, //允许跨域
  70. ws: false, //使用websocket
  71. rewrite: (path) => path.replace(/^\/airopt/, '')
  72. },
  73. '/file': {
  74. // target: 'http://192.168.0.15:8081/', // 后端接口地址
  75. target: 'http://192.168.0.43:2201/',
  76. secure: false, //接受使用https
  77. changeOrigin: true, //允许跨域
  78. ws: false, //使用websocket
  79. pathRewrite: { // 路径重写
  80. '^/file': ''
  81. }
  82. }, '/websokct': {
  83. target: 'http://192.168.0.104:8188',
  84. // target: 'http://192.168.0.43:8081/',
  85. // target: 'https://www.gzchain.org.cn/managersvc/', //后端接口地址
  86. secure: false, //接受使用https
  87. },
  88. }
  89. },
  90. css: {
  91. preprocessorOptions: {
  92. scss: {
  93. silenceDeprecations: ['legacy-js-api']
  94. }
  95. }
  96. }
  97. }
  98. })