import {defineConfig} from 'vite';
import laravel from 'laravel-vite-plugin';
import React from '@vitejs/plugin-react';
import viteCompression from 'vite-plugin-compression';
import svgr from 'vite-plugin-svgr';

export default defineConfig({
    plugins: [laravel({
        input: ['resources/js/app.jsx'], refresh: false,
        // 构建ssr
        ssr: 'resources/js/ssr.jsx',
    }), React(), viteCompression(), svgr()], server: {
        port: 3008, host: '127.0.0.1', proxy: {
            '/admin-api': 'http://dexnav-main.test'
        },
    }, optimizeDeps: {
        esbuildOptions: {
            loader: {'.tsx': 'jsx'}
        }
    },
    resolve: {
        alias: {
            '@': '/resources'
        }
    },
    build: {
        minify: 'terser', // 混淆器，terser构建后文件体积更小
        terserOptions: {
            compress: {
                //生产环境时移除console
                drop_console: true,
                // drop_debugger: true,
            },
            output: {
                // 去掉注释内容
                comments: false,
            },
        },
        rollupOptions: {
            output: {
                manualChunks: {
                    // 拆分代码，这个就是分包，配置完后自动按需加载
                    // react: ['react'],
                    // 'tdesign-react': ['tdesign-react'],
                },
            },
        },
    },
});
