Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree-shaking dynamic imports #4318

Closed
surma opened this issue Mar 12, 2020 · 2 comments 路 Fixed by #5367
Closed

Tree-shaking dynamic imports #4318

surma opened this issue Mar 12, 2020 · 2 comments 路 Fixed by #5367

Comments

@surma
Copy link

surma commented Mar 12, 2020

馃檵 feature request

I am wondering if it has ever been considered to enable tree-shaking on dynamic imports. As a starter: If (and only if) every import of a module is easily statically analyzable, the same dead code elimination routines as they are used for static imports could be run.

If it is not easily analyzable, Parcel could always fall back to the current behavior. The resulting bundle sizes should remain same size or get smaller!.

Example

const { logCaps } = await import('./utils.js');
//utils.js
export function logCaps(msg) {
  console.log(msg.toUpperCase());
}

export function thisIsNeverCalled(msg) {
  return msg + '!';
}

Example repo

@kzc
Copy link

kzc commented Mar 21, 2020

Related discussion: rollup/rollup#3417 (comment)

@devongovett
Copy link
Member

devongovett commented Mar 24, 2020

With pure ESM this should be possible. We'd need to move the analysis of used imports to the bundling phase instead of the packaging phase though. It currently happens here. cc @mischnic I think you were running into something related today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants