vite.config.js 3.12 KB
Newer Older
左玲玲's avatar
左玲玲 committed
1 2 3 4 5 6 7 8 9 10
/*
 * @Author: zuolingling zuolingling@jsnangao.com
 * @Date: 2023-08-10 16:13:33
 * @LastEditors: zuolingling zuolingling@jsnangao.com
 * @LastEditTime: 2023-08-11 15:48:28
 * @FilePath: \vue3portal\vite.config.js
 * @Description: 
 * 
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
 */
wuhao's avatar
wuhao committed
11 12
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
左玲玲's avatar
左玲玲 committed
13 14
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
wuhao's avatar
wuhao committed
15
import path from "path"
左玲玲's avatar
左玲玲 committed
16 17 18
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
wuhao's avatar
wuhao committed
19 20
export default defineConfig({
  server: {
左玲玲's avatar
左玲玲 committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    host: '127.0.0.1',
    cors: true,
    proxy: {
      '/mes/': { // 匹配请求路径,localhost:3000/snow
        target: 'http://gateway.nangaoyun.com:8000/portal', // 代理的目标地址
        changeOrigin: true, // 开发模式,默认的origin是真实的 origin:localhost:3000 代理服务会把origin修改为目标地址
        // rewrite target目标地址 + '/abc',如果接口是这样的,那么不用重写
        rewrite: (path) => path.replace(/^\/mes/, '') // 路径重写,本项目不需要重写
      },
      "/mesc/": {
        // 要代理的地址
        target: "http://gateway.nangaoyun.com:8080",  //39:18040    23/mes/   //60 翔
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/mesc/, '') // 路径重写,本项目不需要重写
      },
    }
wuhao's avatar
wuhao committed
37 38
  },
  resolve: {
左玲玲's avatar
左玲玲 committed
39 40
    alias: {
      "@": path.resolve(__dirname, "src"),
wuhao's avatar
wuhao committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
      "@static": path.resolve(__dirname, "static"),
      "@assets": path.resolve(__dirname, "src/assets"),
      "@mixins": path.resolve(__dirname, "src/mixins"),
      "@comps": path.resolve(__dirname, "src/components"),
      "@views": path.resolve(__dirname, "src/views"),
      "@plugins": path.resolve(__dirname, "src/plugins"),
      "@utils": path.resolve(__dirname, "src/utils"),
      "@api": path.resolve(__dirname, "src/api"),
    },

  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
左玲玲's avatar
左玲玲 committed
56
        additionalData: `
wuhao's avatar
wuhao committed
57 58 59 60
          @import "${path.resolve(__dirname, './node_modules/ayin-lessmixins/ayin-lessmixins.less')}";
          @import "${path.resolve(__dirname, './node_modules/ayin-color/ayin-color.less')}";
          @import "${path.resolve(__dirname, './node_modules/ayin-color/ayin-color-expand.less')}";
          `
左玲玲's avatar
左玲玲 committed
61
        //引入的less全局变量,来自于开源组件ayin-color和ayin-lessmixins,访问https://www.npmjs.com/package/ayin-color 查看相关信息
wuhao's avatar
wuhao committed
62 63 64 65
      }
    }
  },
  optimizeDeps: {
左玲玲's avatar
左玲玲 committed
66
    include: ['echarts', 'ayin-color'],
wuhao's avatar
wuhao committed
67 68
    exclude: ['techui-vue3-lite']
  },
左玲玲's avatar
左玲玲 committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  plugins: [
    vue(),
    AutoImport({
      resolvers: [
        ElementPlusResolver(),
        // 自动导入图标组件
        IconsResolver({
          prefix: 'Icon',
        })
      ],
    }),
    Components({
      resolvers: [
        ElementPlusResolver(),
        // 自动注册图标组件
        IconsResolver({
          enabledCollections: ['ep'],
        })
      ]
    }),
    Icons({
      autoInstall: true,
    }),
  ]
wuhao's avatar
wuhao committed
93
})