webview’s preload script cannot be found in production
See original GitHub issueMy preload.js
file is in src/components/MyComponent
folder. And my other file containing webview
is like following:
const getSourceDirectory = () =>
process.env.NODE_ENV === "development"
? path.join(process.cwd(), "src/components/MyComponent") // or wherever your local build is compiled
: path.join(process.resourcesPath) // asar location
const preload = `file://${path.resolve(getSourceDirectory(), 'preload.js')}`
And I include it like:
<webview
preload={preload}
src="https://google.com"
/>
This works in development
because I know the path. I can’t seem to find the path in production
though.
And if I put the same path as development
, i.e, "src/components/MyComponent"
then it says Can’t find preload.js
which is obvious.
How do I make this thing work in production
with electron-forge
?
I know the error is in the else
condition of the ternary operator, i.e, path.join(process.resourcesPath)
should be changed to something else but what should it be changed to?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:14 (5 by maintainers)
Top Results From Across the Web
webview's preload script cannot be found in production #1590
My preload.js file is in src/components/MyComponent folder. And my other file containing webview is like following: const getSourceDirectory ...
Read more >Preload not working/compiled correctly in production (Electron ...
To me it seems the issue is that your project structure is slightly wrong. The static directory is supposed to be located in...
Read more >Breaking Changes | Electron
If your preload scripts do not depend on Node, no action is needed. If your preload scripts do depend on Node, either refactor...
Read more >Link types: preload - HTML: HyperText Markup Language | MDN
The preload value of the element's rel attribute lets you declare fetch requests in the HTML's , specifying resources that your page will ......
Read more >Build Options - Vite
build.modulePreload # ... Note: the polyfill does not apply to Library Mode. If you need to support browsers without native dynamic import, you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Using the “magic” variables worked for me as long as I used what @deadcoder0904 mentioned:
With the magic global variable:
This isn’t documented as far as I can tell: https://www.electronforge.io/config/plugins/webpack#project-setup Hope this helps someone, this worked for me from the fresh “Webpack” variety starting point.
I have the same problem.