Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] why use library mode to bundle main process #249

Open
kingyue737 opened this issue Aug 13, 2024 · 1 comment
Open

[Question] why use library mode to bundle main process #249

kingyue737 opened this issue Aug 13, 2024 · 1 comment

Comments

@kingyue737
Copy link

kingyue737 commented Aug 13, 2024

This plugin uses library mode to bundle the main and renderer process. I wonder what the considerations are.

lib: options.entry && {

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',
              },
            },
          },
        },
      },
 ]
@caoxiemeihao
Copy link
Member

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.

@kingyue737 kingyue737 changed the title [Question] why use library mode to bundle main and renderer process [Question] why use library mode to bundle main process Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants