Switch to module imports for smaller bundle size #372
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR significantly reduces the bundle size of the library (from ~1280KB -> ~490KB) without breaking changes.
If you take a look at https://github.com/highcharts/highcharts-angular#highcharts-instance-details, you can see that users are meant to choose a single Highcharts core from
highcharts
,highmaps
,highstock
, andhighcharts-gantt
. If you want to use features from multiple cores, you should choose Highcharts and then use modules to add on the additional feature sets. This is what this library currently does.However, the chart classes currently use the core imports instead of the module imports. The core imports are much larger (as they contain duplicate code), and 3/4 of them aren't actually being used at runtime. I switched the imports over to use the modules, and it's helped reduce the bundle size significantly:
(screenshots from the sample app analysed with
source-map-explorer
)Before:
After:
It would be great if someone could test this out on their existing Highstocks/Highmaps/Highcharts Gantt app to make sure that nothing breaks.
I also made a branch which uses secondary imports to support the use of alternative core modules and tree shaking, but it would have been a major breaking change. I'm happy to clean that branch up if there's interest, but this gets us 80% of the way there practically for free.