Skip to content

Treeshaking is not implemented in metro, yet there is a tree shaking option in the plugin config. How does this work? #2922

Answered by tido64
karimb11 asked this question in Q&A
Discussion options

You must be logged in to vote

The Metro flow goes something like this:

flowchart LR
    Parse --> Transform --> Serialize --> Write
Loading

Our plugins are run inside the "Serialize" step. By this step, Metro is done transforming all source code and is ready to write to disk. We take all the transformed code and pass it to esbuild for yet another pass. The output of this pass is then written to disk.

As you can probably see, it is a bit hacky. I wish there was a better way to implement tree shaking in Metro right now, but it's going to take a while to do it correctly. That said, we are using it in a number of products, including Office apps if I remember correctly.

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@kelset
Comment options

@karimb11
Comment options

@tido64
Comment options

Answer selected by tido64
@karimb11
Comment options

@tido64
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants