Is there any way you can stop moment.js
from loading all the locales (I just need English) when you're using webpack? I'm looking at the source and it seems that if hasModule
is defined, which it is for webpack, then it always tries to require()
every locale. I'm pretty sure this needs a pull request to fix. But is there any way we can fix this with the webpack config?
Here is my webpack config to load momentjs:
resolve: {
alias: {
moment: path.join(__dirname, "src/lib/bower/moment/moment.js")
},
},
Then anywhere I need it, I just do require('moment')
. This works but it's adding about 250 kB of unneeded language files to my bundle. Also I'm using the bower version of momentjs and gulp.
Also if this can't be fixed by the webpack config here is a link to the function where it loads the locales. I tried adding && module.exports.loadLocales
to the if
statement but I guess webpack doesn't actually work in a way where that would work. It just require
s no matter what. I think it uses a regex now so I don't really know how you would even go about fixing it.
nmp
instead ofbower
? – Andreas Köberle