Moment from Agnostic Library imported in Angular App ignores Moment.locales

Viewed 34

I created an agnostic core library shared by many angular projects which uses Rollup.js as module Bundler.

The library imports and uses moment. Both projects(Core/Angular) are sharing the same version of moment.

2.29.1

In my angular Project I plugged locale moment as below :

moment.locale(lang); // lang -> dynamic

Internal use of moment works well in angular project but all variables created from the library do not use the locale configuration.

For example: I have english translation from core instead of Spanish translation configured from Angular App.

Any Idea?

Thanks for your help.

1 Answers

It works!

Package.json

"peerDependencies": { "moment": "^2.29.1" },

rollup.config.ts


const external = [
    ...Object.keys(pkg.dependencies || {}),
    ...Object.keys(pkg.peerDependencies || {}),
  ];

Then add external to your config

Related