Open ynnelson opened 1 year ago
I had this issue as well, looks like the plugin is bundling the preload script with the same webpack configuration used by the main script by default (https://github.com/electron/forge/pull/2679), so react-refresh-webpack-plugin
and its dependencies end up in the bundled preload.js
.
Since I'm not using the preload script (yet), adding an empty object as the preload webpack configuration worked for me:
new WebpackPlugin({
devServer: { liveReload: false },
mainConfig,
renderer: {
config: rendererConfig,
entryPoints: [
{
html: './src/index.html',
js: './src/renderer.ts',
name: 'main_window',
preload: {
js: './src/preload.ts',
config: {} // => add this
},
},
],
},
}),
Maybe the main, renderer, and preload files should be moved to separate folders inside /src
and the webpack configs for each of them should only look for files inside that folder to avoid this? š¤
I'm using preload script to load react. Any way to workaround this issue when using preload script? š
@Rychu-Pawel try this:
preload: {
js: './src/preload.ts',
config: {
...rendererConfig,
plugins: [],
},
}
@erikian this works like a charm!! Thank you so much š» my life is going to get so much easier now š š“ šø
Pre-flight checklist
Electron Forge version
6.0.3
Electron version
21.3.1
Operating system
macOS 12.4
Last known working Electron Forge version
No response
Expected behavior
Expected not to have issues after adding React Refresh and to not have the entire window refresh every time. I expected to only have the one component refreshed and not the whole window.
I am trying to understand how to run React Refresh within Electron Forge properly, I searched the existing issues and this is where I got my forge.config.ts file updates from aka setting liveReload to false but I seem to still be getting some errors.
I'd appreciate some guidance to get it to work appropriately. Also before adding React Refresh I did not get the
__dirname is not defined
error or theUnable to load preload script
error.Actual behavior
When I do
yarn run start
I get the below errors in the console:Steps to reproduce
package.json
forge.config.ts
wepbpack.plugin.ts
Additional information
No response