More and more modern Typescript transpilers have moved toward a strategy of per-module transpilation, which significantly increases build speed, but eliminates the possibility for cross-module const enum
usage, since transpilation of them requires type information.
I have a significant amount of const enums
that when used without the inlining that const
provides:
- End up being hundreds of KBs even after minification due to long property names
- Leak internal, backend property names that I don't want public
Right now I have these const enum
definitions auto generated from backend native code. As a contrived example, you can imagine I work at Apple and have a great big const enum of every hardware device.
const enum HardwareType {
Apple1 = 0,
// ...
iPhoneX = 412,
// ...
iPhoneUltraXD = 499, // Some theoretical unannounced iPhone
}
If I just change const enum HardwareType
to enum HardwareType
, in addition to bumping up my bundle size, I've now leaked the new "iPhone Ultra XD" to the public.
I see that something like Terser supports the --mangle-props
option, but even that seems to be warned against in the official docs and also would mean creating a regex that covers every single HardwareType
? Not to mention that's just my contrived example and I have dozens of these enums in reality with hundreds of values.
I'd really like to use the latest tech for application bundling, but is there really not a better option out there for compile time inlining of constant values?