electron / electron/forge

webview’s preload script cannot be found in production

Open
#1,590 15 comments 3 reactions 0 assignees View on GitHub
plugin/webpack
Dominant language
TypeScript
Stars
7.1k
Forks
641
Avg merge
3d 17m
Merged PRs (30d)
32

Description

My `preload.js` file is in `src/components/MyComponent` folder. And my other file containing `webview` is like following:

```js
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:

```js

```

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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.