My requirejs config is declaring moment.js and I'd like to set the default locale when requiring the library. So, I've tried this :
require.config({
enforceDefine: true,
noGlobal: true,
baseUrl: '/js',
shim: {
'moment': {
init: function (moment) {
console.log("*** Moment loaded!");
return moment;
}
}
},
paths: {
'moment': 'lib/moment-with-locales.min'
}
});
However, calling require(['moment'], function (moment) { ... }); does not invoke the init function inside the shim configuration.
What am I not getting, here?
Moment.js defines itself as an AMD module and RequireJS won't call init.
From the documentation of RequireJS:
The
initfunction will not be called for AMD modules. For example, you cannot use a shim init function to call jQuery'snoConflict. See Mapping Modules to use noConflict for an alternate approach to jQuery.
From the master source of Moment.js:
https://github.com/moment/moment/blob/develop/moment.js#L2796
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With