-
Notifications
You must be signed in to change notification settings - Fork 12k
How would you exclude moment.js locale in a proper way? #6137
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
Comments
Just include the .min.js version which does not include any locales, and then include the locale you need.
Edit: Found out that my solution does not work, and in fact also includes all locales |
@ciesielskico thanks for coming back so quick. As SO has already similar question but without the right answer for me so I just decided to ask here hoping to get the best help. Thanks a lot. |
@ciesielskico is your bundle looking good after all? By importing through the P.S
|
just missing typings for |
Please share if you do, I just found out I've got all moment locales as
well.
|
Forked with typings, enjoy: https://github.com/kirillgroshkov/moment-mini-ts
|
This looks very intersting ! How would you import specific locales this way ? |
It's quite difficult to get ride of moment when some packages (like material2) depend on it :( |
Can I import some |
@jesulink2514 Im facing with the same issue. Using material 2, but cannot use material-mini-ts due to dependency. Could you find any solution? |
@petivagyok16 ` globby(['./node_modules/moment/locale/*', '!./node_modules/moment/locale/de.js', '!./node_modules/moment/locale/de-at.js', '!./node_modules/moment/locale/de-ch.js']) |
There is a simplier solution if you want to exlude all locales, in
It will instruct the compiler to use the minified-without-locale bundle instead of building from the sources. Why use this instead of
|
@TomDemulierChevret |
@TomDemulierChevret thanks for sharing this. But I am receiving below warning when I build my app:
|
@MikeDabrowski I'm not sure, but you should just need to import the locales you need (see https://momentjs.com/docs/#/i18n/loading-into-browser/). @naveedahmed1 I have the same warning but haven't faced any issue yet. As long as you don't use functionnality from moment that requires locales, this shouldn't be an problem. |
I tried |
@katzz0 ignore-plugin demo shows how to ignore all locale files, but how to preserve one, for example, 'fr' |
I found a solution in momentjs issues, then I tried it with ./extra-webpack.config.js
and angular.json
It works fine. You can select whatever locale you want. Hope this will help you. |
@dreamdevil00 Nice. One question that i can't figure out. The webpack devDependency must be aligned with the one used by Angular CLI or did you just used @latest for that? |
@danieldiazastudillo Just require webpack, needn't to install webpack as devdependency again. |
how did you ignorePlugin warning? I'm using angular6 and haven't been able to suppress the ./locale warning |
@DavidDon13 Please use this solution solution |
For anyone else with this redundant-moment-weight-problem, I highly recommend using DayJS: I'm just gonna leave this here, in case anyone needs more persuasion: |
@FrogMonkeyBird DayJS provide integration with Angular Material? |
I have no idea, sorry - Not an expert in DayJS :) |
@Brandinga
|
For those of you who use moment-timezone there is a trick to reduce the size (if you can get away with 2012-2022 dates):
Note that you don't have to include I wrote a blog post that ties all this stuff together, and also includes moment timezone. |
I have tried the solution above. I'm using Sorry, but i'm confused, is this supposed to work with Thanks in advance! |
@ktsangop This is working with moment-timezone. In one of my current projet I have this config : "compilerOptions": {
"paths": {
"plotly.js": [
"../node_modules/plotly.js/dist/plotly-basic.min.js"
],
"moment": [
"../node_modules/moment/min/moment.min.js"
],
"moment-timezone": [
"../node_modules/moment-timezone/builds/moment-timezone-with-data-2012-2022.min.js"
]
}
} Wich leads to these sizes once gziped :
Without the above config, I get :
As you can see, the difference is quite substantial. 😄 SidenotePlotly is one of the best (if not the best) chart library available : MIT license + nearly every possible chart type + reaaaaally deep customisation If you want to use it (or any chart library), you should definitly include it in a lazy-loaded module and not in your root module. |
@TomDemulierChevret Thank you so much for the response.
I build the project using this : |
My dependencies are quite similar to yours :
I also use webpack-bundle-analyzer (3.0.3) for the bundle. There must be something wrong with your |
BTW, i cannot apply the
|
Seems like i had another (internal) lib that was also dependent on moment... |
I managed to get moment.min.js loading but what is the best practice to lazy load the language that I want to use? I use Angular's i18n feature with one configuration per language (currently 'de' and 'en') which results in two apps (one for each language). I tried using the |
Yes i too experienced same! Trying other approaches now... |
I did the dirty way :) I simply deleted the unwanted locales from "\node_modules\moment\locale", and everything went well in production. 1st, I created tools/delete-moment-locale.js: var fs = require('fs');
}; 2nd) I called this code before my npm run build code in package.json:
|
@keserwan this is the kind of tool they need to make that strips all except locales specified. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request
Versions.
Details
I've got the whole locale ended up in my bundle:
As I am not using
--eject
flag this solution moment/moment#2416 (comment) in not working for me.I discovered this SO answer which is kind of not really works for me, getting like
Error: Can't resolve './locale'
in runtime.Is there any proper solution with
angular-cli
to exclude themoment
locale
without--eject
?The text was updated successfully, but these errors were encountered: