vite-plugin-electron icon indicating copy to clipboard operation
vite-plugin-electron copied to clipboard

Vite ignoring resolve.mainFields in configuration

Open vembye opened this issue 2 years ago • 3 comments

Problem

Using the default config, vite doesn't seem to respect the resolve.mainField.

We are using ws in our electron setup, and when using vite-plugin-electron vite kept importing the browser module from ws, corrupting the build.

Seeing the correct approach in default config, ignoring the browser as a mainField. Unfortunately vite kept using the browser field.

Turns out resolve.mainField is not respected when targeting browser (which is vite default).

Solution

Enforce main entry build to be ssr: true.

I'm ready to create PR if issue is accepted.

vembye avatar Feb 15 '24 07:02 vembye

Hey! 👋 However, you can override the default configuration by configuring electron({}) in vite.cinfig.ts.

caoxiemeihao avatar Mar 13 '24 11:03 caoxiemeihao

Definitely, and how we have done it, so change not required to get it working.

But debugging of multiple hours to figure out why the (already existing) clause of handling browser field didn't take effect, could have been avoided, and should for new-comers IMO 💡

It would have saved me a lot of frustrations at least 🙏🏻

vembye avatar Mar 13 '24 20:03 vembye

Are you talking about import the ws module in the Renderer process? If the Main process import the ws module, it will not look for the browser module. The default config only acting on Main process and Preload scripts.

caoxiemeihao avatar Mar 14 '24 02:03 caoxiemeihao