[Tech] Use compile-time constants for isWindows
, isMac
and isLinux
#3944
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.
When building Heroic, we know which platform we're building for at all times (the current platform when running
pnpm start
, the target platform when runningdist:win
,dist:mac
, etc.). Because of this, we can tell Vite about that platform (with a specialmode
), and in turn replace constants likeisWindows
with literal values (true
/false
). This then allows Rollup to do tree-shaking (it will completely eliminate code paths and even entire dependencies if they're not used)Rollup sadly seems rather peculiar about when it'll do this tree-shaking:
gets removed as expected, but
does not. As such, we'll have to move towards
if
-based checks (if (isWindows) { /* ... */ } else if (isMac) { /* ... */ }
) instead ofswitch
-based checks (switch (process.platform) { case 'win32': /* ... */ }
) to get the most out of this featureUse the following Checklist if you have changed something on the Backend or Frontend: