github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/ui/vite.config.js (about)

     1  import { defineConfig } from 'vite'
     2  import WindiCSS from 'vite-plugin-windicss'
     3  import tsConfigPath from 'vite-tsconfig-paths'
     4  import reactPlugin from '@vitejs/plugin-react'
     5  import { visualizer } from 'rollup-plugin-visualizer'
     6  
     7  import { reactRouterPlugin } from './plugins/vite-plugin-next-react-router'
     8  import { i18nextScanner } from './plugins/vite-plugin-i18next-scanner'
     9  import packageJson from './package.json'
    10  
    11  function renderChunks(deps) {
    12    let chunks = {}
    13    Object.keys(deps).forEach(key => {
    14      if (['react', 'react-router-dom', 'react-dom'].includes(key)) return
    15      chunks[key] = [key]
    16    })
    17    return chunks
    18  }
    19  
    20  // https://vitejs.dev/config/
    21  export default defineConfig({
    22    base: '/dashboard/',
    23    plugins: [
    24      reactPlugin(),
    25      WindiCSS(),
    26      tsConfigPath(),
    27      reactRouterPlugin({ async: false }),
    28      i18nextScanner({ langs: ['en', 'zh'] }),
    29    ],
    30    server: {
    31      port: 8080,
    32      proxy: {
    33        '/api/v1': {
    34          target: 'http://172.16.6.148:8261',
    35          changeOrigin: true,
    36        },
    37      },
    38    },
    39    css: {
    40      preprocessorOptions: {
    41        less: {
    42          javascriptEnabled: true,
    43        },
    44      },
    45    },
    46    build: {
    47      rollupOptions: {
    48        plugins: [visualizer({ template: 'treemap' })],
    49        output: {
    50          manualChunks: {
    51            vendor: ['react', 'react-router-dom', 'react-dom'],
    52            ...renderChunks(packageJson.dependencies),
    53          },
    54        },
    55      },
    56    },
    57  })