Drop useless moment locales from built file

This commit is contained in:
Lucas Verney 2018-07-12 16:47:19 +02:00
parent f17f672de6
commit 0d6df10fbd
4 changed files with 20 additions and 4 deletions

View File

@ -1,4 +1,5 @@
'use strict'
const fs = require('fs')
const path = require('path')
const svg2png = require('svg2png')
const utils = require('./utils')
@ -15,6 +16,18 @@ 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: {
rules: utils.styleLoaders({
@ -126,6 +139,9 @@ const webpackConfig = merge(baseWebpackConfig, {
minChunks: 3
}),
// Only keep the useful locales from Moment.
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, localesRegex),
// copy custom static assets
new CopyWebpackPlugin([
{

View File

@ -69,9 +69,9 @@ module.exports = {
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// `ANALYZE=true yarn build`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report,
bundleAnalyzerReport: process.env.ANALYZE,
// OpenGraph-related variables
ogURL: 'https://cyclo.phyks.me',

View File

@ -70,7 +70,7 @@
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-bundle-analyzer": "^2.13.1",
"webpack-dev-server": "^2.9.1",
"webpack-merge": "^4.1.0"
},

View File

@ -6707,7 +6707,7 @@ wbuf@^1.1.0, wbuf@^1.7.2:
dependencies:
minimalistic-assert "^1.0.0"
webpack-bundle-analyzer@^2.9.0:
webpack-bundle-analyzer@^2.13.1:
version "2.13.1"
resolved "https://registry.yarnpkg.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-2.13.1.tgz#07d2176c6e86c3cdce4c23e56fae2a7b6b4ad526"
dependencies: