简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM