Tree shaking for cross-module inlined enum values does not work
See original GitHub issueDescribe the bug
I want to use const enums
instead of enum
to optimize transpiled code, but it only works in a single file. When I use ESM import/export syntax for cross-module inlining, it does not work.
I have tried to use rollup
to implement this, and it can work. And now I want to know if this is a bug of Vite
.
Reproduction
https://stackblitz.com/edit/vitejs-vite-7lxty9
Steps to reproduce
No response
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 7.17.0 - /usr/local/bin/npm
npmPackages:
@vitejs/plugin-vue: ^3.1.2 => 3.1.2
vite: ^3.1.4 => 3.1.6
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
[Feature] Inline const enum values in TypeScript #128 - GitHub
Tree shaking for cross-module inlined enum values has been implemented. This feature should now work the way I intend for it to work....
Read more >Why does Webpack 5 include my unused TypeScript enum ...
Simply replacing enum variable with const (Record Utility) fixed the issue and Tree Shaking was visible in the production bundle.
Read more >evanw/esbuild v0.14.9 on GitHub - NewReleases.io
Implement cross-module tree shaking of TypeScript enum values (#128). If your bundle uses TypeScript enums across multiple files, esbuild is able to inline...
Read more >Tree-shakeable enums in Typescript-based ES modules
Here I want to focus on tree shaking. Tree shaking is a term commonly used in the JavaScript context for dead-code elimination. –...
Read more >02.24.2022 - TypeScript/Enums at runtime and tree-shaking
A heterogeneous enum is the type of enum where you can have a mix between numeric and string values. Numeric enums are compiled...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Would you provide a reproduction of this?
Oh, I got it. Thank you very much.