Skip to content

Commit

Permalink
Merge pull request #4042 from ovangle:fix-4031
Browse files Browse the repository at this point in the history
[bugfix] Make auto locale loading for node not mess webpack, fixes #4031, #2979, #3872
  • Loading branch information
ichernev committed Aug 7, 2017
2 parents e2fcca2 + 8d2df8c commit 49819dc
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/lib/locale/locales.js
Expand Up @@ -50,13 +50,21 @@ function loadLocale(name) {
// TODO: Find a better way to register and load all the locales in Node
if (!locales[name] && (typeof module !== 'undefined') &&
module && module.exports) {
oldLocale = globalLocale._abbr;
try {
oldLocale = globalLocale._abbr;
require('./locale/' + name);
// because defineLocale currently also sets the global locale, we
// want to undo that for lazy loaded locales
getSetGlobalLocale(oldLocale);
} catch (e) { }
require('moment/locale/' + name);
} catch (e) {
// In the test environment, the external module 'moment'
// can't be resolved because we're running inside it.
// Fallback to using the old relative import
try {
require('./locale/' + name);
} catch (e) { }
}

// because defineLocale currently also sets the global locale, we
// want to undo that for lazy loaded locales
getSetGlobalLocale(oldLocale);
}
return locales[name];
}
Expand Down

0 comments on commit 49819dc

Please sign in to comment.