forge: webpack: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY is not defined
- I have read the contribution documentation for this project.
- I agree to follow the code of conduct that this project follows, as appropriate.
- I have searched the issue tracker for an issue that matches the one I want to file, without success.
Please describe your issue:
I’m using the repo provided by @tgds found here. While it is in typescript rather than JS, it works no problem using the MAIN_WINDOW_WEBPACK_ENTRY
variable.
The documentation for the webpack plugin says
For an entry point with the name main_window two variables will be defined MAIN_WINDOW_WEBPACK_ENTRY and MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY
with this example:
const mainWindow = new BrowserWindow({
webPreferences: {
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
}
});
mainWindow.loadUrl(MAIN_WINDOW_WEBPACK_ENTRY);
However, if I modify the code in the repo provided to match, I get an error:
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (3 by maintainers)
What worked for me was:
I found it by looking at the repository related to another reported bug. It would be truly appreciated if you could update the documentation a little bit - I was searching for hours to find a way how tu use typescript in the preload script.
It only says that I should use the variable
MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY
but says nothing where it comes from and what should I do to initialize it.Also it’d be very helpful to explain the magic behind the naming.
Hey Guys, it really IS described in the docs, but very hidden. https://www.electronforge.io/config/plugins/webpack#project-setup
if you DON’T define the preload-script in the package.json then you only have by default only one variable autogenerated - MAIN_WINDOW_WEBPACK_ENTRY.
if you DO define the preload-script in the package.json, there will be 2 variables autogenerated for you now ( as described in the docs): MAIN_WINDOW_WEBPACK_ENTRY and MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY - prefixed with MAIN_WINDOW because you defined the entrypoint-name as “main_window” in your package.json.
in order to use these variable now in your index.ts / main-process-script they have to be declared upfront: <<(index.ts)>>
<<(package.json)>>
Fun detail to add: if you change the entry point name, the name of this variable also changes. So with:
The variables would be called:
To be honest, I do not understand why this is not pre-generated. At least, it would be nice to have something like that in the generated index.ts:
@karlitos That was works for me to in “dev”
electron-forge start
script. But when I build distribution using @electron-forge/maker-squirrelelectron-forge make
do not loaded the preload.ts, it does not appear on .webpack folder.My package.json:
My index.ts
Can anybody help me? @MarshallOfSound @karlitos
For now, thanks!
That is inaccurate, it’s part of https://www.electronforge.io/config/plugins/webpack#project-setup
@G-Rath
MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY
will only be defined if a preload is defined in your@electron-forge/plugin-webpack
config.Their is no preload configured here --> https://github.com/tgds/electrong-forge-webpack-typescript/blob/master/package.json#L42-L46 so that variable is not set. I’ll update the docs now