question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tree shaking for cross-module inlined enum values does not work

See original GitHub issue

Describe 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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sapphi-redcommented, Oct 9, 2022

I have tried to use rollup to implement this, and it can work.

Would you provide a reproduction of this?

0reactions
shy-robincommented, Oct 10, 2022

Oh, I got it. Thank you very much.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found