vite.config.ts 3.8 KB

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