Solvedvue chartjs Standalone chartjs build (don't include moment.js)
โ๏ธAccepted Answer
Oh damn, really? So I'm stuck with having moment.js in my project even though I never use it. It's literally the largest chunk in my whole project. Thanks for your answer though!
Update:
I was able to exclude it by using
vue.config.js
configureWebpack: {
externals: {
moment: 'moment'
}
}
I don't know if it has any other impacts besides moment.js is gone and my full project shrunk by about 250kb.
Other Answers:
That is because if you import Chart from 'chart.js'
you will get the bundled one (with moment.js).
There are some issues at chart.js to kill moment.js and replace it with date-fns. However I don't know if it will happend.
I would love to change that, however it would be confusing to break with the standard behaviour of the chart.js npm package. So the solution needs to be on user side right now.
๐ Solution
You need to add an alias to your webpack config, so it will grab the standalone version
webpack.config.js
resolve: {
alias: {
'chart.js': 'chart.js/dist/Chart.js'
}
}
This way it will grab the standalone version.
Expected Behavior
Moment.js shouldn't be included
Actual Behavior
Moment.js appears on my package.lock file and gets bundled in my build
Environment
Can you help me figure out how I configure this correctly so that I only get the standalone chart.js build: https://github.com/chartjs/Chart.js/blob/3e94b9431a5b3d6e4bfbfd6a2339a350999b3292/docs/getting-started/installation.md . Moment.js is a very heavy package and if I can avoid including it in my site I'll gladly do that. The documentation makes it sound like treeshaking can do this but I'm just using the vue webpack cli and it's still coming through.
Thanks