feat: Use production build of react in packaged app #329
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently we are using the development build of react in the packaged
app. The development build is slower, see:
https://reactjs.org/docs/optimizing-performance.html
The fix is a little complicated: Normally you would build a bundle (including React) with
process.env.NODE_ENV = 'production'
. However, we use webpack withtarget='electron-renderer'
and this loads all modules as externals e.g. they are required at runtime rather than included in a single bundle. Thewebpack.environmentPlugin()
does not setNODE_ENV
for runtime, it only replaces the variable in moduels included in the bundle (react isn't included, because it is 'external').The hacky workaround is to patch in
process.env.NODE_ENV = 'production'
to the output bundle from webpack. A better long-term solution might be to bundle all code for electron, which might also result in a smaller build size and faster loading (lots ofrequire
calls has an overhead, especially on slow machines with spinning disk hard drives). This would require filtering out dependencies from the packaged app which are required in the bundle.TL;DR this change should make the app more responsive (snappier™) and should work well enough for now.