Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add way to remove moment from build #1108

Closed
almgwary opened this issue May 6, 2019 · 13 comments
Closed

Add way to remove moment from build #1108

almgwary opened this issue May 6, 2019 · 13 comments

Comments

@almgwary
Copy link

almgwary commented May 6, 2019

Moment js increase the bundle size, add option to remove it while build

Moment.js is installed along Chart.js as dependency. If you don't want to use Moment.js (either because you use a different date adapter or simply because don't need time functionalities), you will have to configure your bundler to exclude this dependency (e.g. using externals for Webpack or external for Rollup).

https://github.com/chartjs/Chart.js/blob/f2b099b835bf5d6dfe3a7d3097997ec11983c3ed/docs/getting-started/integration.md#L28

@almgwary
Copy link
Author

almgwary commented May 6, 2019

@paviad check this

@paviad
Copy link
Contributor

paviad commented May 6, 2019

I am not proficient in webpack, moment is indeed a part of chart.js therefore I have no easy way to get rid of it in ng2-charts...

@almgwary
Copy link
Author

almgwary commented May 6, 2019

You can import standalone version - not bundled one with the following line:

import Chart from 'chart.js/dist/Chart.js'

Or setting alias

resolve: {
    alias: {
      'chart.js': 'chart.js/dist/Chart.js'
    }
}

@paviad
Copy link
Contributor

paviad commented May 6, 2019

But I do not include chart.js as a dependency but as a peer dependency - so it is up to the user to include all of chart.js or just the bare package without the bundle.

@almgwary
Copy link
Author

almgwary commented May 8, 2019

But I do not include chart.js as a dependency but as a peer dependency - so it is up to the user to include all of chart.js or just the bare package without the bundle.

you should change the chart.js import at base-chart.directive
to be like this

import * as chartJs from 'chart.js/dist/Chart.bundle.js'

this should solve the problem

@naveedahmed1
Copy link

Any update on this? This can save 574.32 Kb. With chart.js 2.8 it should now be possible.
chartjs/Chart.js#5960

I would also like to know if we can also remove lodash.js dependency?

@M-Blobby
Copy link

I'm also interested about any update. I'm in the same situation with naveedahmed1.

@AceVentura
Copy link

Hello,

Any updates on this?

@almgwary
Copy link
Author

Hello,

Any updates on this?

Copy the base directive in your project and apply the following update

#1108 (comment)

@AceVentura
Copy link

Hello,
Any updates on this?

Copy the base directive in your project and apply the following update

#1108 (comment)

That would require me to copy the code from github. I'm using the npm package

@paviad
Copy link
Contributor

paviad commented Aug 26, 2020

Wait, what is wrong with this import in base-chart.directive.ts:

import {
  Chart,
  ChartConfiguration,
  ChartDataSets,
  ChartOptions,
  ChartPoint, ChartType,
  PluginServiceGlobalRegistration,
  PluginServiceRegistrationOptions,
  pluginService
} from 'chart.js';

@AlecDusheck
Copy link

You can use a custom webpack configuration to mark moment as an external package. This can be accomplished by installing/configuring the @angular-builders/custom-webpack package and then including this custom webpack config:

module.exports = {
  externals: {
    moment: 'moment',
  },
}

@santam85
Copy link
Contributor

santam85 commented Mar 1, 2024

fixed in v3+

@santam85 santam85 closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants