-
Notifications
You must be signed in to change notification settings - Fork 109
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
How to not bundle all moment locales #114
Comments
Ugh. This thread opens so hopefully with the moment and webpack maintainers trying to work out a solution, and ends so ignominiously with the webpack maintainers closing the issue "because it's not about webpack". You can certainly use any of the strategies they talk about. I tested moment-locales-webpack-plugin like this and it works: // in ember-cli-build.js
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
let app = new EmberApp(defaults, {
autoImport: {
webpack: {
plugins: [
new MomentLocalesPlugin({
localesToKeep: ['es-us', 'ru'],
})
]
}
}
}); So that provides an immediate solution for your application, but it's unsatisfactory as a good ecosystem-wide solution. I consider it a bug if app authors need to provide webpack-specific config to do normal, common things. I see two action items here:
|
@ef4 thank you so much for the quick reply!
Since we can use the solutions advised by webpack I don't think this is a bug of e-a-i. Regarding ember-cli-moment-shim it will be easy to use e-a-i internally using the code above as a guide. @cibernox you might want to add this to your readme also so your calendar users are not loading all locales by default. @ef4 thank you again for the help! |
I do consider it a bug though, because I don't really want @cibernox to need to tell all users of his addon to manually add stuff to the webpack config. We should come up with a convention between ember addons to control this stuff. I'm also thinking forward to when this kind of capability is built into ember-cli. I see ember-auto-import as a polyfill for eventually building whole ember apps with this kind of automated module resolution. |
Maybe the best option would be to make the shim use e-a-i and let it transform the user options for locales and timezones into the proper webpack config. |
I am trying to auto import moment.js, and I'm not sure how to debug this error:
I tried it with @ef4 locales solution (FWIW, I do not need multiple locales), but still see the same error. Any examples on getting this to work? Here's some code: return import('moment').then(({ default: moment }) => {
const effective = this.get('effective');
if (effective) {
return moment(effective).utc().format('LL');
}
return 'To be determined';
}); I am currently using |
since this issue was created, The readme there has a section on how to control what moment brings in: https://github.com/adopted-ember-addons/ember-moment#controlling-locale-and-timezone-data, which aligns with moment's own docs on how to use it with webpack. |
How can I prevent moment from being imported twice?
I added "moment" to the exclude array and it stopped importing moment because of my app, but it is still importing it because of an addon I use:
my project -> ember-power-calendar -> ember-power-calendar-moment -> moment
I'm using the ember-cli-moment-shim because ember-auto-import imports all the locales and the shim let's me control that, if there is a way to control which locales are imported I might stop using the shim and all will be good
EDIT:
Found other posts about this regarding webpack, this seems to be a way of ignoring the locales but I'm not sure how to do it with e-a-i: moment/moment#1435 (comment)
More info: https://webpack.js.org/plugins/context-replacement-plugin/
Thanks in advance!
The text was updated successfully, but these errors were encountered: