mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 11:20:07 +08:00
refactor: improve environment variable handling in electron.vite.config.ts
- Introduced `isDev` and `isProd` constants for clearer environment checks. - Simplified sourcemap and noDiscovery settings based on environment. - Enhanced esbuild configuration for production to drop console and debugger statements.
This commit is contained in:
parent
a3d6f32202
commit
b265c640ca
@ -8,6 +8,9 @@ const visualizerPlugin = (type: 'renderer' | 'main') => {
|
|||||||
return process.env[`VISUALIZER_${type.toUpperCase()}`] ? [visualizer({ open: true })] : []
|
return process.env[`VISUALIZER_${type.toUpperCase()}`] ? [visualizer({ open: true })] : []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isDev = process.env.NODE_ENV === 'development'
|
||||||
|
const isProd = process.env.NODE_ENV === 'production'
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
main: {
|
main: {
|
||||||
plugins: [externalizeDepsPlugin(), ...visualizerPlugin('main')],
|
plugins: [externalizeDepsPlugin(), ...visualizerPlugin('main')],
|
||||||
@ -21,17 +24,21 @@ export default defineConfig({
|
|||||||
build: {
|
build: {
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: ['@libsql/client', 'bufferutil', 'utf-8-validate', '@cherrystudio/mac-system-ocr'],
|
external: ['@libsql/client', 'bufferutil', 'utf-8-validate', '@cherrystudio/mac-system-ocr'],
|
||||||
output: {
|
output: isProd
|
||||||
// 彻底禁用代码分割 - 返回 null 强制单文件打包
|
? {
|
||||||
manualChunks: undefined,
|
manualChunks: undefined, // 彻底禁用代码分割 - 返回 null 强制单文件打包
|
||||||
// 内联所有动态导入,这是关键配置
|
inlineDynamicImports: true // 内联所有动态导入,这是关键配置
|
||||||
inlineDynamicImports: true
|
}
|
||||||
}
|
: {}
|
||||||
},
|
},
|
||||||
sourcemap: process.env.NODE_ENV === 'development'
|
sourcemap: isDev
|
||||||
|
},
|
||||||
|
esbuild: {
|
||||||
|
drop: ['console', 'debugger'],
|
||||||
|
legalComments: 'none'
|
||||||
},
|
},
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
noDiscovery: process.env.NODE_ENV === 'development'
|
noDiscovery: isDev
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
preload: {
|
preload: {
|
||||||
@ -42,7 +49,7 @@ export default defineConfig({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
sourcemap: process.env.NODE_ENV === 'development'
|
sourcemap: isDev
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
renderer: {
|
renderer: {
|
||||||
@ -60,14 +67,7 @@ export default defineConfig({
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
// 只在开发环境下启用 CodeInspectorPlugin
|
...(isDev ? [CodeInspectorPlugin({ bundler: 'vite' })] : []), // 只在开发环境下启用 CodeInspectorPlugin
|
||||||
...(process.env.NODE_ENV === 'development'
|
|
||||||
? [
|
|
||||||
CodeInspectorPlugin({
|
|
||||||
bundler: 'vite'
|
|
||||||
})
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
...visualizerPlugin('renderer')
|
...visualizerPlugin('renderer')
|
||||||
],
|
],
|
||||||
resolve: {
|
resolve: {
|
||||||
@ -95,6 +95,12 @@ export default defineConfig({
|
|||||||
selectionAction: resolve(__dirname, 'src/renderer/selectionAction.html')
|
selectionAction: resolve(__dirname, 'src/renderer/selectionAction.html')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
esbuild: isProd
|
||||||
|
? {
|
||||||
|
drop: ['console', 'debugger'],
|
||||||
|
legalComments: 'none'
|
||||||
|
}
|
||||||
|
: {}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user