How to build tree-shakeable JavaScript libraries

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • InfluxDB - Build time-series-based applications quickly and at scale.
  • Sonar - Write Clean JavaScript Code. Always.
  • Zigi - Workflow assistant built for devs & their teams
  • Scout APM - Truly a developer’s best friend
  • Chart.js

    Simple HTML5 Charts using the <canvas> tag

    In Chart.js, tree-shaking didn’t work as expected because of assignments to class properties (replaced with static properties).

  • chartist

    Simple responsive charts

    (Full disclosure: this is a real-world design decision from Chartist, an open-source data visualization library I maintain and contribute to.)

  • InfluxDB

    Build time-series-based applications quickly and at scale.. InfluxDB is the Time Series Data Platform where developers build real-time applications for analytics, IoT and cloud-native services in less time with less code.

  • size-limit

    Calculate the real cost to run your JS app or lib to keep good performance. Show error in pull request if the cost exceeds the limit.

    However, you can use the Size Limit library to control the size of a bundle or individual exports. Here’s an example configuration:

  • terser

    🗜 JavaScript parser, mangler and compressor toolkit for ES6+

    You can see that the div function was copied “as is” and is not used in any way. When you run Webpack in production mode, it will remove this function. (Internally, Webpack relies on Terser for minification; Rollup performs tree-shaking and dead code elimination on its own.)

  • Rollup

    Next-generation ES module bundler

    You can see that the div function was copied “as is” and is not used in any way. When you run Webpack in production mode, it will remove this function. (Internally, Webpack relies on Terser for minification; Rollup performs tree-shaking and dead code elimination on its own.)

  • react-chartjs-2

    React components for Chart.js, the most popular charting library

    In react-chartjs-2, some exported entities are constructed by calling a factory method (marked as pure).

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts