import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import path from 'path'; import tailwindcss from '@tailwindcss/vite'; const isDev = process.env.NODE_ENV === 'development'; const centerEnv = process.env.CENTER_ENV; const plugins: any[] = []; plugins.push(tailwindcss()); const meBackend = 'https://kevisual.xiongxiao.me'; let target = meBackend || 'http://localhost:51515'; const apiProxy = { target: target, changeOrigin: true, ws: true, rewriteWsOrigin: true, secure: false, cookieDomainRewrite: 'localhost' }; let proxy = { '/root/': apiProxy, '/api': apiProxy, '/client': apiProxy, }; // https://vitejs.dev/config/ export default defineConfig({ plugins: [react(), ...plugins], css: { postcss: {}, }, resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, define: { DEV_SERVER: JSON.stringify(process.env.NODE_ENV === 'development'), CENTER_ENV: JSON.stringify(centerEnv), }, base: isDev ? '/' : '/root/center-v1/', build: { sourcemap: false, rollupOptions: { output: { // 控制输出 // 在rollup里面, hash代表将你的文件名和文件内容进行组合计算得来的结果 assetFileNames: (chunkInfo) => { console.log(chunkInfo.names); if (chunkInfo.names?.includes('panda.jpg')) { return '[name].[ext]'; } const qrcode = ['qrcode-8x8.jpg']; const names = chunkInfo.names || []; if (qrcode.some((name) => names.includes(name))) { return '[name].[ext]'; } return '[name].[hash].[ext]'; }, manualChunks(id) { if (id.includes('node_modules')) { if (id.includes('react')) { return 'vendor-react'; } // prettier if (id.includes('prettier')) { return 'vendor-prettier'; } // codemirror // console.log(id); return 'vendor'; } }, }, }, }, server: { port: 6020, host: '0.0.0.0', proxy: { '/root/locales': { target: 'https://kevisual.cn', changeOrigin: true, }, '/system/lib': { target: 'https://kevisual.xiongxiao.me', changeOrigin: true, }, ...proxy, }, }, });