fix: Improve moment include in locales (fix #1628)
This commit is contained in:
Родитель
1dd7dfeb2b
Коммит
519886156b
|
@ -50,15 +50,18 @@ poFiles.forEach((pofile) => {
|
|||
var defineLocale = null;
|
||||
try {
|
||||
const momentLocale = locale.replace('_', '-').toLowerCase();
|
||||
const localeModulePath = `moment/locale/${momentLocale}`;
|
||||
// Check for the locale first; if it doesn't exist we don't have
|
||||
// a moment locale that matches.
|
||||
fs.accessSync(`./node_modules/${localeModulePath}.js`);
|
||||
|
||||
// We're using `new Function()` here to create a function out of the
|
||||
// raw code in this file; this function won't be executed but will be
|
||||
// written out by `toSource()` so that it can be used later (at runtime,
|
||||
// by moment).
|
||||
defineLocale = new Function(
|
||||
fs.readFileSync(
|
||||
`./node_modules/moment/locale/${momentLocale}.js`, 'utf8'
|
||||
)
|
||||
);
|
||||
// raw code; this function won't be executed but will be written out by
|
||||
// `toSource()` so that it can be used later (at runtime, by moment).
|
||||
defineLocale = new Function(`
|
||||
// By requiring this module, the new locale is defined and
|
||||
// registered internally for moment.js
|
||||
require('${localeModulePath}');`);
|
||||
} catch (e) {
|
||||
// We ignore missing locale errors for en_US as its moment's default
|
||||
// locale so we don't need to provide a translation.
|
||||
|
|
|
@ -113,8 +113,6 @@ export default Object.assign({}, webpackConfig, {
|
|||
}),
|
||||
// Replaces server config module with the subset clientConfig object.
|
||||
new webpack.NormalModuleReplacementPlugin(/config$/, 'core/client/config.js'),
|
||||
// Prevent locales with moment require calls from crashing
|
||||
new webpack.NormalModuleReplacementPlugin(/\.\.\/moment$/, 'moment'),
|
||||
// This allow us to exclude locales for other apps being built.
|
||||
new webpack.ContextReplacementPlugin(
|
||||
/locale$/,
|
||||
|
|
|
@ -84,8 +84,6 @@ const settings = {
|
|||
}),
|
||||
// Replaces server config module with the subset clientConfig object.
|
||||
new webpack.NormalModuleReplacementPlugin(/config$/, 'core/client/config.js'),
|
||||
// Prevent locales with moment require calls from crashing
|
||||
new webpack.NormalModuleReplacementPlugin(/\.\.\/moment$/, 'moment'),
|
||||
// Substitutes client only config.
|
||||
new webpack.NormalModuleReplacementPlugin(/core\/logger$/, 'core/client/logger.js'),
|
||||
// Use the browser's window for window.
|
||||
|
|
Загрузка…
Ссылка в новой задаче