Skip to content

Just building the Electron files not working as expected #308

Open

Description

@cmahnke

Certainly I', missing something but the usual Vite plugin usage pattern with apply doesn't seem to work:

  plugins: [
    {
      ...electron({
        main: {
          entry: "src/electron/main.ts"
        },
        preload: {
          input: "src/electron/preload.ts"
        }
      }),
      apply: "build"
    }
  ],

Activity

  1. subframe7536 commented on Aug 13, 2026

    @subframe7536
    Contributor

    electron() returns Plugin[].

    You should use like this:

    import { defineConfig } from 'vite'
    import electron from 'vite-plugin-electron/simple'
    
    export default defineConfig(({ command }) => ({
      plugins: [
        command === 'build' &&
          electron({
            main: {
              entry: 'src/electron/main.ts',
            },
            preload: {
              input: 'src/electron/preload.ts',
            },
          }),
      ],
    }))
  2. cmahnke commented on Aug 13, 2026

    @cmahnke
    Author

    Thanks, wouldn't it be nice if it works like documented by the Vite docs?

  3. subframe7536 commented on Aug 14, 2026

    @subframe7536
    Contributor

    Since "electron()" returns a plugin array, you can directly pick the build plugin with "find":

    plugins: [
      electron({
        main: {
          entry: 'src/electron/main.ts',
        },
        preload: {
          input: 'src/electron/preload.ts',
        },
      }).find(plugin => plugin.apply === 'build'),
    ]
    

    The returned preset already contains separate plugins with "apply: 'serve'" and "apply: 'build'", so there is no need to overwrite "apply" manually.

    The only way to make override work is make plugin returns a single plugin object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions