[Question] why use library mode to bundle main process
kingyue737 opened this issue · 1 comments
This plugin uses library mode to bundle the main and renderer process. I wonder what the considerations are.
vite-plugin-electron/src/utils.ts
Line 30 in f6dabc3
Firstly, Vite library mode includes opinionated configuration for browser-oriented libraries which may not suitable for the main and renderer processes which are not modules to be imported by other modules.
Secondly, if the output is ESM, it won't be minified (white spaces are kept) in lib mode, which is a long-lived issue of Vite.
In my opinion, directly using rollup to bundle may be a better choice like stated in https://vitejs.dev/guide/backend-integration.html
For example
build: [
{
vite: {
plugins: isDev ? [notBundle()] : [esmShim()],
build: {
minify: isProd,
commonjsOptions: {
ignoreDynamicRequires: true,
},
// disable vite-plugin-electron default lib mode
lib: false,
rollupOptions: {
// overwrite default .html entry
input: 'electron/main.ts',
output: {
entryFileNames: '[name].js',
},
},
},
},
},
]
Just because the build.lib
API is so simple, the default configuration is more suitable for building a Node.js/Electron application.
The renderer process does not use the build.lib
API, and it is not even interfered by vite-plugin-electron
.
Thanks for your suggestion, I will consider this suggestion in the future.