From bc88f56f433c1b8c211bf99acb33885a7b51dfa6 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Tue, 21 Jul 2020 21:28:39 +0300 Subject: [PATCH] Improve chunks for locales --- .gitlab-ci.yml | 4 ++-- webpack.config.js | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dcc975f..5ef597b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -188,9 +188,9 @@ Build: - find . -name '*.js' | cpio -pdm ../source-maps/ - cd .. # Cleanup source maps for unimportant bundles + - rm -f source-maps/runtime.js + - rm -f source-maps/intl-polyfills.js - rm -rf source-maps/locale-* - - rm -rf source-maps/intl* - - rm -rf source-maps/vendors~* artifacts: name: "Production build for $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA" paths: diff --git a/webpack.config.js b/webpack.config.js index 28bbd4e..bfb2bd3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -211,11 +211,7 @@ const webpackConfig = { }; if (isAnalyze) { - webpackConfig.plugins.push( - new BundleAnalyzerPlugin({ - excludeAssets: /^(vendors~intl|locale-|intl)/, - }), - ); + webpackConfig.plugins.push(new BundleAnalyzerPlugin()); } if (isProduction) { @@ -250,14 +246,39 @@ if (isProduction) { splitChunks: { cacheGroups: { vendor: { - test: (m) => - String(m.context).includes('node_modules') && - // icons and intl with relateed polyfills are allowed - // to be splitted to other chunks - !/\/(flag-icon-css|intl|@formatjs)\//.test(String(m.context)), name: 'vendors', + priority: 0, + test: (m) => String(m.context).includes('node_modules'), chunks: 'all', }, + polyfills: { + name: 'intl-polyfills', + priority: 1, + chunks: ({ name }) => ['intl', 'intl-pluralrules', 'intl-relativetimeformat'].includes(name), + enforce: true, + }, + ...SUPPORTED_LANGUAGES.reduce((acc, locale) => { + const localePolyfills = [ + `intl-${locale}-js`, + `intl-pluralrules-${locale}-js`, + `intl-relativetimeformat-${locale}-js`, + ]; + + acc[locale] = { + name: `locale-${locale}`, + priority: 1, + chunks: ({ name }) => name === `locale-${locale}-json`, + enforce: true, + }; + acc[`${locale}Polyfill`] = { + name: `locale-${locale}-polyfill`, + priority: 2, + chunks: ({ name }) => localePolyfills.includes(name), + enforce: true, + }; + + return acc; + }, {}), }, }, };