From 3369c30ff4a21ba931bea4d3f2dda35c52c82241 Mon Sep 17 00:00:00 2001 From: pomelo-nwu Date: Mon, 6 Jan 2025 09:48:24 +0800 Subject: [PATCH] feat: fix build --- packages/studio-website/vite.config.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/studio-website/vite.config.ts b/packages/studio-website/vite.config.ts index 75ff9fff..69f01873 100644 --- a/packages/studio-website/vite.config.ts +++ b/packages/studio-website/vite.config.ts @@ -3,6 +3,7 @@ import react from '@vitejs/plugin-react'; import { viteSingleFile } from 'vite-plugin-singlefile'; import dotenv from 'dotenv'; import wasm from 'vite-plugin-wasm'; +import path from 'path'; // 获取传递的参数 const args = process.argv.slice(2); @@ -17,10 +18,21 @@ args.forEach(arg => { const { mode } = params; const isSingle = mode === 'single' && process.env.NODE_ENV === 'production'; -console.log('params', params, args); -const plugins = isSingle ? [react(), viteSingleFile(), wasm()] : [react(), wasm()]; +console.log('params', params, args); +const plugins = isSingle ? [react(), + // viteSingleFile(), + wasm()] : [react(), wasm()]; +const rollupOptions = isSingle ? { + output: { + globals: {}, // 如果有外部依赖,这里定义全局变量映射 + inlineDynamicImports: true, // 内联动态导入,防止拆分 + entryFileNames: `[name].portal.js`, // 不带hash的入口文件名 + chunkFileNames: `[name].portal.js`, // 不带hash的块文件名 + assetFileNames: `[name].portal.[ext]`, // 不带hash的资源文件名 + } +}:{} const { parsed } = dotenv.configDotenv(); const { COORDINATOR_URL } = parsed || {}; @@ -51,10 +63,16 @@ export default defineConfig({ }, build: { // minify: false, + // outDir: './dist', + // rollupOptions: { + // external: ['node:os', 'fsevents'], // 要排除的模块 + // }, + minify: false, outDir: './dist', rollupOptions: { external: ['node:os', 'fsevents'], // 要排除的模块 - }, + ...rollupOptions + } }, plugins, optimizeDeps: {