| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import react from '@vitejs/plugin-react';
- import { defineConfig, loadEnv } from 'vite';
- import removeConsole from 'vite-plugin-remove-console';
- import topLevelAwait from 'vite-plugin-top-level-await';
- import wasm from 'vite-plugin-wasm';
- import { viteBuildInfo } from './build/buildInfo';
- import { configCompressPlugin } from './build/compress';
- import svgConvert from './build/svgConvert';
- import { root, alias, wrapperEnv } from './build/utils';
- // https://vitejs.dev/config/
- export default defineConfig(({ mode }) => {
- const env = wrapperEnv(loadEnv(mode, root));
- const isProd = mode === 'production';
- return {
- base: env.VITE_BUILD_PUBLIC_PATH,
- plugins: [
- react(),
- wasm(),
- topLevelAwait(),
- isProd &&
- removeConsole({
- includes: ['log', 'warn'],
- external: ['error'],
- }),
- svgConvert(),
- viteBuildInfo(),
- configCompressPlugin(env.VITE_BUILD_COMPRESSION!),
- ].filter(Boolean),
- resolve: { alias },
- optimizeDeps: {
- exclude: ['brotli-wasm'],
- },
- css: {
- preprocessorOptions: {
- less: {
- javascriptEnabled: true,
- },
- scss: {
- additionalData: `@use "@/styles/variables" as *;`,
- },
- },
- },
- server: {
- port: env.VITE_DEV_PORT,
- host: '0.0.0.0',
- open: true,
- proxy: {
- '/dev/api/v1': {
- target: env.VITE_DEV_PROXY_TARGET_API_BASE_URL,
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/dev\/api\/v1/, ''),
- secure: false,
- configure: (proxy) => {
- proxy.on('error', (err) => {
- console.log('proxy error', err);
- });
- proxy.on('proxyReq', (_, req) => {
- console.log(
- 'Sending Request to the Target:',
- req.method,
- req.url,
- env.VITE_DEV_PROXY_TARGET_API_BASE_URL
- );
- });
- proxy.on('proxyRes', (proxyRes, req) => {
- console.log(
- 'Received Response from the Target:',
- proxyRes.statusCode,
- req.url
- );
- });
- },
- },
- },
- warmup: {
- clientFiles: ['./index.html', './src/{pages,components}/*'],
- },
- },
- build: {
- outDir: 'dist',
- sourcemap: !isProd,
- target: ['es2015', 'chrome87', 'safari13', 'firefox78', 'edge88'],
- cssTarget: ['chrome87', 'safari13', 'firefox78', 'edge88'],
- rollupOptions: {
- output: {
- manualChunks: {
- 'react-vendor': ['react', 'react-dom', 'react-router-dom'],
- 'antd-vendor': ['antd'],
- 'utils-vendor': ['lodash-es', 'ramda'],
- },
- },
- },
- chunkSizeWarningLimit: 1500,
- },
- };
- });
|