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.

RFC: Add stat reporting for tree-shaken modules

See original GitHub issue

Feature request

If a module is tree-shaken, provide a stat entry field claiming which dependencies have been shaken.

What is the expected behavior?

When studying a module stat, offer the information if a dependency is shaken.

{
  "name": "my-module.js",
  "reasons": [{ filename: "/a/b/c.js", treeShaken: true }, /* ... */]
}

Or similar. This would imply that /a/b/c.js imported my-module.js, but it was shaken from c.js. There are certainly other schemas that could be used instead.

What is motivation or use case for adding/changing the behavior?

I seek to:

  • apply new rules: [{ test: myTest, sideEffects: false }], but need to do an audit of the tree-shaken modules to know that turning on this rule is safe
    • by getting a list of shaken modules, I can do a manual study to assert that no reading/writing from the global scope occurs, and verify that my optimization is safe
    • my project has thousands of modules, so studying each of them is challenging. I want sideEffects: false set for nearly all ESM modules in my codebase, but want to audit those that are pruned with precision (vs many thousands in play). Having reporting will help me see what webpack is optimizing out, and allow me to assert these optimizations are safe before checking in the optimization

How should this be implemented in your opinion?

I assume that webpack already identifies these modules during compilation. Allow for that state to be captured into the Stats interface, so as to help provide diagnostics.

Are you willing to work on this yourself?

Possibly, if given low to mid level coaching on what modules are in play, what edge cases to look out for, etc.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
vankopcommented, Feb 16, 2022

btw there is a plugin that marks modules with sideEffect flag https://github.com/vankop/side-effect-free-webpack-stat-plugin

0reactions
webpack-botcommented, Sep 5, 2022

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tree-Shaking: A Reference Guide - Smashing Magazine
Tree-shaking” is a must-have performance optimization when bundling JavaScript. In this article, we dive deeper on how exactly it works and ...
Read more >
Changelog - Cypress Documentation
Fixed a bug where projects using Node.js 16.17+ and 18.6+ with ES Modules and TypeScript were not working with Cypress. Fixes #22795, #23393,...
Read more >
Tree Shaking - webpack
Tree shaking is a term commonly used in the JavaScript context for dead-code elimination. It relies on the static structure of ES2015 module...
Read more >
Tree shaking - MDN Web Docs Glossary
Tree shaking is a term commonly used within a JavaScript context to describe the removal of dead code.
Read more >
Tree-Shaking Basics for React Applications - Telerik
Tree-shaking is an important way to reduce the size of your bundle and improve performance. See how you can do it in your...
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