-
Notifications
You must be signed in to change notification settings - Fork 43
Feature: Tree shaking #102
Comments
what does tree shaking mean for node? does it delete the stuff from memory that it doesn't need? |
The use case says “Alice is using an existing npm package that is written in CommonJS. She wants to use one specific function exported from its |
I'm not sure how this applies to node - treeshaking isn't part of the spec; despite that bundlers do it, it's often unsafe to do; and any form of "treeshaking" is already identically possible with static CJS as with static ESM - I can't even conceive of how node would do anything to make it harder. |
so like: "whatever code she uses to run her code in node should still be understandable to tree-shaking tools"? |
this is achieved with nothing more than "uses ESM import/export syntax". |
@ljharb thats my understanding as well, i just want to be 100% clear as the original text makes me think that people expect the node vm itself to perform some sort of treeshaking |
It was @jkrems’ use case, so perhaps they could clarify? And feel free to edit my original post to make the request clearer. (This applies to all the feature issues I’m opening.) |
So the first part goes to the heart of ESM being statically analyzable, so that an all-ESM module graph can get pruned so that a bundle with only the used code is generated.
The second part I assume includes code like
import { shuffle } from 'underscore'
(as opposed toimport _ from 'underscore'
) where we know thatshuffle
is the member being imported and so therefore the module graph can include justshuffle
rather than all ofunderscore
. See also #100 (comment)Use case 12.
The text was updated successfully, but these errors were encountered: