I am confused by the following phrasing made by chart.js:
Chart.js is tree-shakeable, so it is necessary to import and register the controllers, elements, scales and plugins you are going to use.
Source: https://www.chartjs.org/docs/latest/getting-started/integration.html
I was under the impression that tree-shaking means the builder itself would determine which things are unused, and then not include those in the build. But if I have to do that myself, then that is no longer tree-shaking, it’s just me minimizing imports.
On the other hand, if what they meant is that you can do something like this:
import { A, B } from "chart.js"
And then if you don’t use A
, it will not be included, then my intuition was why wouldn’t I use chart.js by doing this:
import * as chartjs from "chart.js"
Instead of this:
import { Chart } from "chart.js/auto"
This would give all the benefit of not having to import only used things one-by-one, give access to all components, and still allow for tree-shaking. Is that correct?