Angular Chart.js - 删除 Moment.js 作为依赖项/减少包大小 [英] Angular Chart.js - Remove Moment.js as Dependency / Reduce Bundle Size
问题描述
我正在使用 Chart.js
和 Angualar 7
.
但是 Chart.js
为我的包大小增加了大约 450KB.通过其他资源我发现,Moment.js
是大尺寸的主要因素.
But Chart.js
adds about 450KB to my bundle size. Through other resources I found out, that Moment.js
is the main factor for the big size.
"chart.js": {
"version": "2.7.3",
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-2.7.3.tgz",
"integrity": "sha512-3+7k/DbR92m6BsMUYP6M0dMsMVZpMnwkUyNSAbqolHKsbIzH2Q4LWVEHHYq7v0fmEV8whXE0DrjANulw9j2K5g==",
"requires": {
"chartjs-color": "^2.1.0",
"moment": "^2.10.2"
}
},
我想知道如何从依赖项中删除 moment.js
,以便减少包的大小.
I want to know how to remove moment.js
from the dependencies, so that bundle size will be reduced.
Mybe 有没有办法只从 Chart.js
导入我真正使用的内容?
Mybe there is a way to only import what's I am really using from Chart.js
?
推荐答案
您可以导入独立版本 - 不与以下行捆绑在一起:
You can import standalone version - not bundled one with the following line:
import Chart from 'chart.js/dist/Chart.js'
或者在 web.config 中设置别名:
Or setting alias in web.config:
resolve: {
alias: {
'chart.js': 'chart.js/dist/Chart.js'
}
}
或者安装没有捆绑 moment.js 的 Angular ChartJS:
Or Install Angular ChartJS which does not have moment.js bundled:
https://github.com/emn178/angular2-chartjs
这篇关于Angular Chart.js - 删除 Moment.js 作为依赖项/减少包大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!