electron / electron/forge

[Enhancement] Allow "default" Preload script / Only compile once

Open
#2,336 1 comment 0 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

### Preflight Checklist

* [x] I have read the [contribution documentation](https://github.com/electron-userland/electron-forge/blob/master/CONTRIBUTING.md) for this project.
* [x] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project follows, as appropriate.
* [x] I have searched the issue tracker for a feature request that matches the one I want to file, without success.

### Problem Description

Right now, every preload script is being compiled separately, taking considerable time to finish. I have quite a lot of renderers, but only a single, central preload script. It would be great if we could decrease the time necessary to compile by compiling the preload script only once.

### Proposed Solution

Cache the paths of preload scripts and, if a path already compiled is encountered, simply copy the compiled version to the new target.

### Alternatives Considered

Another possible solution would be to define a "global" preload in a variable, e.g., named `preloadForAllRenderers` that can be set instead of all the default ones. Depending on how easy it is to access the config, this might be easier to implement, and I can guess that there are a few apps out there that only have a single preload script for all renderers.

### Additional Information

While it is absolutely great to have the ability to set separate preload files, I think most apps only need a single preload file for all windows to keep maintainability and the codebase smaller. By allowing either caching or a single global one would increase compile speed for those apps who only need one.

I guess, looking at the code it might be easier to use a default variable which is being used (if set) for all renderers where no specific preload has been defined.

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.