electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.51k stars 521 forks source link

fix(vite-template): fix vite template start failed after package #3713

Closed caoxiemeihao closed 2 weeks ago

caoxiemeihao commented 2 months ago

Summarize your changes:

Closes #3714

Since we removed the copy dependencies logic in vite-plugin of v7.5.0, this will cause if (require('electron-squirrel-startup')) to fail to load. This is because Vite's built-in @rollup/plugin-commonjs cannot handle CommonJS's require() function like Webpack in many cases. We need to make some compromises in code writing and try to use ESModule's import statement to avoid this problem.

If anyone wants to know more about this issue, I wrote an article introducing the problem of Vite building CommonJS format code. 👉🏻 https://github.com/vite-plugin/vite-plugin-commonjs/blob/main/commonjs.zh-CN.md

hichemfantar commented 4 weeks ago

let's merge this bad boy

BlackHole1 commented 3 weeks ago

PTAL @electron/forgers

hichemfantar commented 3 weeks ago

@caoxiemeihao can you explain the changes you’ve made to the type declarations code?

hichemfantar commented 2 weeks ago

hey, this pr removed the vite-forge type declarations in forge.env.d.ts which were broken because the actual declarations file wasn't present in @electron-forge/plugin-vite/forge-vite-env for some reason

i think the packaging process is not including the forge-vite-env.d.ts file for some reason

i added the file and now the reference /// <reference types="@electron-forge/plugin-vite/forge-vite-env" /> in forge.env.d.ts seems to be working correctly

image

image

hichemfantar commented 2 weeks ago

ah looks like the vite const type declarations were fixed in https://github.com/electron/forge/commit/3ad74852700970f06955799f4508fc7bcb86c3f2 but haven't been released yet which fixed the forge-vite-env.d.ts issue