Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Feature: Tree shaking #102

Closed
GeoffreyBooth opened this issue May 20, 2018 · 7 comments
Closed

Feature: Tree shaking #102

GeoffreyBooth opened this issue May 20, 2018 · 7 comments
Labels

Comments

@GeoffreyBooth
Copy link
Member

  • Module bundlers like Rollup can do tree-shaking to create a bundle that includes only the code that’s used.
  • If a member is imported from a CommonJS module using the correct syntax, the tree shaking can include that module.

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 to import _ from 'underscore') where we know that shuffle is the member being imported and so therefore the module graph can include just shuffle rather than all of underscore. See also #100 (comment)

Use case 12.

@devsnek
Copy link
Member

devsnek commented May 20, 2018

what does tree shaking mean for node? does it delete the stuff from memory that it doesn't need?

@GeoffreyBooth
Copy link
Member Author

what does tree shaking mean for node?

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 module.exports and wants to ensure she does it in a way that bundlers will understand while tree-shaking.” So I assume this is only about ensuring that tree-shaking tools can continue to do their thing in a hybrid ESM and CommonJS environment.

@ljharb
Copy link
Member

ljharb commented May 20, 2018

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.

@devsnek
Copy link
Member

devsnek commented May 20, 2018

@GeoffreyBooth

so like: "whatever code she uses to run her code in node should still be understandable to tree-shaking tools"?

@ljharb
Copy link
Member

ljharb commented May 20, 2018

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".

@devsnek
Copy link
Member

devsnek commented May 20, 2018

@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

@GeoffreyBooth
Copy link
Member Author

GeoffreyBooth commented May 20, 2018

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.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants