Fix a bug with Moment locale in production build

This commit is contained in:
Lucas Verney 2018-07-25 11:56:04 +02:00
parent 0bf72e55f4
commit 5063d6d4da
2 changed files with 7 additions and 12 deletions

View File

@ -16,17 +16,6 @@ const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const env = require('../config/prod.env')
// List available locales, to fetch only the required locales from Moment.JS:
// Build a regexp that selects the locale's name without the JS extension (due
// to the way moment includes those) and ensure that's the last character to
// not include locale variants. See discussion in
// https://framagit.org/bnjbvr/kresus/merge_requests/448#note_130514
const locales = fs.readdirSync('src/i18n').filter(x => x != 'index.js').map(
x => x.replace('.js', '')
);
const localesRegex = new RegExp(
'(' + locales.join('|') + ')$'
);
const webpackConfig = merge(baseWebpackConfig, {
module: {
@ -140,7 +129,7 @@ const webpackConfig = merge(baseWebpackConfig, {
}),
// Only keep the useful locales from Moment.
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, localesRegex),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// copy custom static assets
new CopyWebpackPlugin([

View File

@ -1,10 +1,16 @@
import Vue from 'vue';
import VueI18n from 'vue-i18n';
// Moment locales
import 'moment/locale/en-gb';
import 'moment/locale/fr';
// App locales
import en from './en.json';
import fr from './fr.json';
import oc from './oc.json';
// Local moment locales
import './moment/oc';
export const AVAILABLE_LOCALES = [