Angular Chart.js-删除Moment.js作为依赖项/减小捆绑包大小 [英] Angular Chart.js - Remove Moment.js as Dependency / Reduce Bundle Size

查看:49
本文介绍了Angular Chart.js-删除Moment.js作为依赖项/减小捆绑包大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 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.

我也许有一种方法只能从 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆