forge icon indicating copy to clipboard operation
forge copied to clipboard

[plugin-vite] allow custom vite outDir

Open spiotr12 opened this issue 9 months ago • 1 comments

Pre-flight checklist

  • [x] I have read the contribution documentation for this project.
  • [x] I agree to follow the code of conduct that this project uses.
  • [x] I have searched the issue tracker for a feature request that matches the one I want to file, without success.

Problem description

I try to use vite plugin but I have everything configured to output to ./dist. I'm getting following error:

An unhandled rejection has occurred inside Forge:
Error: Electron Forge is configured to use the Vite plugin. The plugin expects the
"main" entry point in "package.json" to be ".vite/*" (where the plugin outputs
the generated files). Instead, it is "dist/electron/src/main.js"

I've check code and search for this issue. Why we cannot specify custom output dir? Why it is hardcoded

my vite.main.config.ts looks like this:

import { defineConfig } from 'vite';
import { viteStaticCopy } from 'vite-plugin-static-copy';

// https://vitejs.dev/config
export default defineConfig({
  build: {
    outDir: './dist/electron/src/',
  },
  plugins: [
    viteStaticCopy({
      targets:[
        {
          src: './projects/electron/package.json',
          dest: '../'
        }
      ]
    }),
  ],
});

Proposed solution

Allow for custom baseDir

Alternatives considered

Remove hardcoded code

Additional information

No response

spiotr12 avatar Feb 27 '25 12:02 spiotr12

I have this issue as well.

Another webpack user had this issue and they forked: https://github.com/electron/forge/issues/2770

paulm17 avatar Mar 12 '25 20:03 paulm17

Subscribing. Should definitely be done for webpack as well.

And replying to the comment on the other issue...

I'm curious as to the actual use case of this

  • Preferences. It's a top-level directory in my repository, which is a quite privileged spot to hold.
  • IDEs usually don't hide paths starting with ., so it's something I'll always see when there are artifacts.
  • On top of that, directories starting with . appear at the top in most IDEs, so it's something extra for you to skip when scanning through the file tree
  • I can't place the output of all build tools in the project in the same e.g. dist or target directory
  • And finally, that's a pretty basic configuration to have.

gustavohenke avatar Sep 17 '25 20:09 gustavohenke