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
+32 -7
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';
const {params} = HashNavigation.parseUrlHash(window.location.hash); // 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 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
+49 -41
View File
@@ -1,45 +1,53 @@
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: {
devtool: 'source-map', index: path.resolve(__dirname, 'src/index.js'),
module: { },
rules: [ devtool: 'source-map',
{ module: {
test: /\.jsx?$/, rules: [
loaders: [ {
'babel-loader', test: /\.jsx?$/,
], loaders: [
exclude: /node_modules/, 'babel-loader',
}, ],
], exclude: /node_modules/,
},
optimization: {
minimizer: [
// we specify a custom UglifyJsPlugin here to get source maps in production.
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
compress: true,
mangle: true
}, },
sourceMap: true ],
}) },
] output: {
}, path: path.resolve(__dirname, 'umd'),
performance: { filename: `[name].${mode}.js`,
maxEntrypointSize: 280000, publicPath: '/umd/'
maxAssetSize: 280000 },
}, optimization: {
externals: { minimizer: [
'react': 'React', // we specify a custom UglifyJsPlugin here to get source maps in production.
'react-dom': 'ReactDOM', new UglifyJsPlugin({
'react-intl': 'ReactIntl', cache: true,
'firebase/app': 'firebase', parallel: true,
'firebase/messaging': ['firebase', 'messaging'] uglifyOptions: {
}, compress: true,
}; mangle: true
},
sourceMap: true
})
]
},
performance: {
maxEntrypointSize: 250000,
maxAssetSize: 250000
},
externals: {
'react': 'React',
'react-dom': 'ReactDOM',
'react-intl': 'ReactIntl',
'firebase/app': 'firebase',
'firebase/messaging': ['firebase', 'messaging']
},
};
}