Newer
Older
HuangJiPC / vite.config.js
@zhangdeliang zhangdeliang on 21 Jun 4 KB update
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import path from 'path';
import { viteMockServe } from 'vite-plugin-mock';
import viteCompression from 'vite-plugin-compression';

export default defineConfig({
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
  resolve: {
    alias: {
      // 导入文件夹别名
      '@': path.resolve(__dirname, 'src'),
    },
  },
  plugins: [
    vue(),
    vueJsx({}),
    viteMockServe({
      supportTs: false,
      logger: false,
      mockPath: './src/mock/',
    }),
    // 开启gzip压缩
    viteCompression({
      threshold: 1024 * 800, // 对大于800kb的文件进行压缩
      algorithm: 'gzip', // 采用的压缩算法,默认是 gzip
      ext: '.gz', // 生成的压缩包后缀
    }),
  ],
  server: {
    port: 8863,
    host: '0.0.0.0',
    proxy: {
      '/api': {
        target: 'http://192.168.16.100:6068/huangji/', //陈迁 16.100
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
      '/huangji_v1': {
        target: 'http://192.168.16.100:6068/huangji', //陈迁 16.100
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/huangji_v1/, ''),
      },
      '/geoServers': {
        target: 'http://server1.wh-nf.cn:8023',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/geoServers/, ''),
      },
      '/WuDiServers': {
        target: 'http://192.168.16.158:8090',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/WuDiServers/, ''),
      },
      '/hongSuAPI': {
        target: 'http://106.14.0.121:8005/BaseApi/api',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/hongSuAPI/, ''),
      },
      '/hongSu2API': {
        target: 'http://106.14.0.121:8001',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/hongSu2API/, ''),
      },
      '/hongSuRainAPI': {
        target: 'http://139.196.225.242:7002/BaseApi',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/hongSuRainAPI/, ''),
      },
      '/hongSuRain2API': {
        target: 'http://139.196.225.242:7002/MonitoringApi',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/hongSuRainAPI/, ''),
      },
      '/DDH_Videos': {
        target: 'http://58.48.82.114:60001/DDHWebServer',
        ws: false, // proxy websockets
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/DDH_Videos/, ''),
      },
      '/YunTuUrl': {
        target: 'http://server1.wh-nf.cn:6083',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/YunTuUrl/, ''),
      },
      // 数公基代理
      '/models-rest/rest/models/preview': {
        target: 'http://192.168.10.50:8863',
        changeOrigin: true,
      },
      '/3dtiles': {
        target: 'http://192.168.10.50:8863',
        changeOrigin: true,
      },
      // 市信息处接口代理
      '/drainage-v3': {
        target: 'http://192.168.10.50:8863', //http://172.16.238.79
        changeOrigin: true,
      },
      '/stationApi': {
        target: 'http://192.168.10.50:8863', //http://172.16.238.79
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/stationApi/, ''),
      },
      '/mapboxfont': {
        target: 'http://192.168.10.48:8869',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/mapboxfont/, ''),
      },
      '/mapApiUrl': {
        target: 'http://192.168.10.33:1234',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/mapApiUrl/, ''),
      },
    },
    fs: {
      strict: false,
    },
  },
  configureWebpack: {
    externals: {
      BMap: 'BMap',
    },
  },
  // 打包文件设置
  build: {
    sourcemap: false,
    outDir: 'dist',
    rollupOptions: {
      output: {
        chunkFileNames: 'assets/js/[name]-[hash].js',
        entryFileNames: 'assets/jsEntry/[name]-[hash].js',
        assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
      },
      brotliSize: true, // 不统计
      target: 'esnext',
      minify: 'esbuild', // 混淆器,terser构建后文件体积更小
    },
  },
  // 清除debugger
  terserOptions: {
    compress: {
      drop_debugger: true,
    },
  },
});