experimenting with code splitting

This commit is contained in:
or-else
2019-09-22 21:32:32 +03:00
parent a2747b6e33
commit 10bb206d51
7 changed files with 307 additions and 129 deletions
+31 -6
View File
@@ -3,22 +3,47 @@
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import { IntlProvider, addLocaleData } from 'react-intl'; import { IntlProvider, addLocaleData } from 'react-intl';
import ruData from 'react-intl/locale-data/ru'; const reactIntlLocaleData = {
addLocaleData(ruData); zh: () => import(/* webpackChunkName: "locale_zh" */ 'react-intl/locale-data/zh'), // Chinese simplified.
ru: () => import(/* webpackChunkName: "locale_ru" */ 'react-intl/locale-data/ru'), // Russian.
en: () => import(/* webpackChunkName: "locale_en" */ 'react-intl/locale-data/en') // English, default.
};
// import enLocale from 'react-intl/locale-data/en';
// Russian
// import ruLocale from 'react-intl/locale-data/ru';
// Chinese simplified.
// import zhLocale from 'react-intl/locale-data/zh';
// addLocaleData([...enLocale, ...ruLocale, ...zhLocale]);
import allMessages from './messages.json'; import allMessages from './messages.json';
import TinodeWeb from './views/tinode-web.jsx'; import TinodeWeb from './views/tinode-web.jsx';
import HashNavigation from './lib/navigation.js'; import HashNavigation from './lib/navigation.js';
// Detect human language to use in the UI:
// Check parameters from URL hash #?hl=ru, then browser, then use 'en' as a fallback.
const { params } = HashNavigation.parseUrlHash(window.location.hash); const { params } = HashNavigation.parseUrlHash(window.location.hash);
const language = (params && params.hl) || const language = (params && params.hl) ||
(navigator.languages && navigator.languages[0]) || (navigator.languages && navigator.languages[0]) ||
navigator.language || navigator.language ||
navigator.userLanguage; navigator.userLanguage ||
'en';
const baseLanguage = language.toLowerCase().split(/[-_]+/)[0]; console.log("== Got language", language);
// Gets the base language 'en' from a more specific 'en_GB' or 'en-US' as a partial fallback.
const baseLanguage = language.toLowerCase().split(/[-_]/)[0];
// Dynamically load locale data for the selected language.
const localeDataLoader =
reactIntlLocaleData[language] ||
reactIntlLocaleData[baseLanguage] ||
reactIntlLocaleData['en'];
localeDataLoader().then((data) => {
addLocaleData(data);
});
// Try full locale, try locale without region code, fallback to 'en' // Try full locale, try locale without region code, fallback to 'en'
const messages = const messages =
+1 -1
View File
@@ -289,7 +289,7 @@
"action_report_contact": "Сообщить о нарушении", "action_report_contact": "Сообщить о нарушении",
"action_report_group": "Сообщить о нарушении" "action_report_group": "Сообщить о нарушении"
}, },
"zh-CN": { "zh": {
"archived_contacts": "已归档联系人 ({count})", "archived_contacts": "已归档联系人 ({count})",
"contacts_not_found": "你尚无会话<br />¯∖_(ツ)_/¯", "contacts_not_found": "你尚无会话<br />¯∖_(ツ)_/¯",
"full_name_prompt": "全名,例如张伟", "full_name_prompt": "全名,例如张伟",
+222 -77
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+14 -6
View File
@@ -1,10 +1,12 @@
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const path = require('path'); const path = require('path');
module.exports = { module.exports = (env, argv) => {
entry: [ const mode = argv.mode === 'production' ? 'prod' : 'dev';
path.resolve(__dirname, 'src/index.js'), return {
], entry: {
index: path.resolve(__dirname, 'src/index.js'),
},
devtool: 'source-map', devtool: 'source-map',
module: { module: {
rules: [ rules: [
@@ -17,6 +19,11 @@ module.exports = {
}, },
], ],
}, },
output: {
path: path.resolve(__dirname, 'umd'),
filename: `[name].${mode}.js`,
publicPath: '/umd/'
},
optimization: { optimization: {
minimizer: [ minimizer: [
// we specify a custom UglifyJsPlugin here to get source maps in production. // we specify a custom UglifyJsPlugin here to get source maps in production.
@@ -32,8 +39,8 @@ module.exports = {
] ]
}, },
performance: { performance: {
maxEntrypointSize: 280000, maxEntrypointSize: 250000,
maxAssetSize: 280000 maxAssetSize: 250000
}, },
externals: { externals: {
'react': 'React', 'react': 'React',
@@ -43,3 +50,4 @@ module.exports = {
'firebase/messaging': ['firebase', 'messaging'] 'firebase/messaging': ['firebase', 'messaging']
}, },
}; };
}