vite.config.ts 4.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import { defineConfig } from 'vite';
import path from 'path';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import eslint from 'vite-plugin-eslint';
import legacy from '@vitejs/plugin-legacy';
// import { visualizer } from 'rollup-plugin-visualizer'; // 打包内容分析
import IBizVitePlugin from './vite-plugins/ibiz-vite-plugin';

/**
 * 判断是否为浏览器原生组件
 *
 * @author chitanda
 * @date 2023-07-05 09:07:39
 * @param {string} tag
 * @return {*}  {boolean}
 */
function isCustomElement(tag: string): boolean {
  return tag.startsWith('ion-');
}

// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  optimizeDeps: {
    entries: [
      '@ibiz-template-package/vs-tree-ex',
      '@ibiz-template/core',
      '@ibiz-template/mob-theme',
      '@ibiz-template/mob-vue3-components',
      '@ibiz-template/model-helper',
      '@ibiz-template/runtime',
      '@ibiz-template/theme',
      '@ibiz-template/vue3-util',
      '@ibiz/model-core',
      'async-validator',
      'dayjs',
      'echarts',
      'ionicons',
      'lodash-es',
      'pinia',
      'qs',
      'qx-util',
      'ramda',
      'vant',
      'vue',
      'vue-i18n',
53
      'vue3-hash-calendar',
54 55 56
      'vue-router',
    ],
  },
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  build: {
    rollupOptions: {
      external: [
        'vant',
        'vue',
        'vue-router',
        'vue-i18n',
        'async-validator',
        'dayjs',
        'echarts',
        'axios',
        'qs',
        'ramda',
        'lodash-es',
        'qx-util',
        'pinia',
73
        'mqtt/dist/mqtt.min',
74 75 76 77 78
        'cherry-markdown',
        '@ibiz-template-package/vs-tree-ex',
        '@ibiz-template/core',
        '@ibiz-template/runtime',
        '@ibiz-template/vue3-util',
79
        '@ibiz-template/mob-theme',
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
        '@ibiz-template/model-helper',
        '@ibiz-template/mob-vue3-components',
      ],
    },
  },
  server: {
    proxy: {
      '/api/sztrainsys__mob': {
        rewrite(path) {
          return path.replace('/api', '');
        },
        target: 'http://172.16.240.140:20086',
        changeOrigin: true,
      },
      '/api/ls__lsmob/remotemodel': {
        rewrite(path) {
          return path.replace('/api/ls__lsmob/remotemodel', '/ls__lsmob/model');
        },
98
        target: 'http://localhost:20003',
99 100 101 102 103 104
        changeOrigin: true,
      },
      '/api/ls__lsmob': {
        rewrite(path) {
          return path.replace('/api/ls__lsmob', '/api');
        },
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
        target: 'http://localhost:8081',
        changeOrigin: true,
      },
      '/api/pms__sclpmsmob': {
        // rewrite(path) {
        //   return path.replace('/api/pms__sclpmsmob', '/api');
        // },
        target: 'http://172.16.103.158:30164/',
        changeOrigin: true,
      },
      '/api/demosys__mobvue3/portal/mqtt/mqtt': {
        rewrite(path) {
          return path.replace('/api', '');
        },
        target: 'ws://172.16.103.169:30350',
        changeOrigin: true,
      },
      '/api/demosys__mobvue3': {
        rewrite(path) {
          return path.replace('/api', '/api');
        },
        target: 'http://172.16.103.169:30350',
        changeOrigin: true,
      },
      '/api/cxfhmgmt__cxfhappmob': {
        rewrite(path) {
          return path.replace('/api', '');
        },
        target: 'http://172.16.103.158:30086',
        changeOrigin: true,
      },
      '/api/qdehr__qdehrapp/portal/mqtt/mqtt': {
        rewrite(path) {
          return path.replace('/api', '');
        },
        ws: true,
        target: 'ws://172.16.240.140:46020',
        changeOrigin: true,
      },
      '/api/qdehr__qdehrapp': {
        rewrite(path) {
          return path.replace('/api', '');
        },
        target: 'http://172.16.240.140:46020',
149 150
        changeOrigin: true,
      },
151 152 153 154
      '/api/gsldrcapmgmt__gsldrcapappmob': {
        target: 'http://172.16.103.158:30200',
        changeOrigin: true,
      },
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
    },
    cors: true,
    fs: {
      strict: false,
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@ibiz-template/theme/style/global.scss";',
      },
    },
  },
  plugins: [
    eslint({
      include: 'src/**/*.{ts,tsx,js,jsx}',
    }),
    vue({
      template: {
        compilerOptions: {
          isCustomElement,
        },
      },
    }),
    vueJsx(),
    legacy({ externalSystemJS: true }),
    IBizVitePlugin(),
    // visualizer(),
  ],
});