mirror of https://github.com/vector-im/riot-web
Revert "Tidy up Service Worker, only run Workbox in production"
This reverts commit c47532fe
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/15352/head
parent
87c42934ea
commit
1edbe36547
|
@ -28,6 +28,11 @@ require('highlight.js/styles/github.css');
|
||||||
import {parseQsFromFragment} from "./url_utils";
|
import {parseQsFromFragment} from "./url_utils";
|
||||||
import './modernizr';
|
import './modernizr';
|
||||||
|
|
||||||
|
// load service worker if available on this platform
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
navigator.serviceWorker.register('service-worker.js');
|
||||||
|
}
|
||||||
|
|
||||||
async function settled(...promises: Array<Promise<any>>) {
|
async function settled(...promises: Array<Promise<any>>) {
|
||||||
for (const prom of promises) {
|
for (const prom of promises) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -34,17 +34,6 @@ const POKE_RATE_MS = 10 * 60 * 1000; // 10 min
|
||||||
export default class WebPlatform extends VectorBasePlatform {
|
export default class WebPlatform extends VectorBasePlatform {
|
||||||
private runningVersion: string = null;
|
private runningVersion: string = null;
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
// load service worker if available on this platform
|
|
||||||
// Service worker is disabled in development: https://github.com/GoogleChrome/workbox/issues/1790
|
|
||||||
if ('serviceWorker' in navigator && process.env.NODE_ENV === "production") {
|
|
||||||
navigator.serviceWorker.register('service-worker.js');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
getHumanReadableName(): string {
|
getHumanReadableName(): string {
|
||||||
return 'Web Platform'; // no translation required: only used for analytics
|
return 'Web Platform'; // no translation required: only used for analytics
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,84 +31,6 @@ module.exports = (env, argv) => {
|
||||||
const reactSdkSrcDir = path.resolve(require.resolve("matrix-react-sdk/package.json"), '..', 'src');
|
const reactSdkSrcDir = path.resolve(require.resolve("matrix-react-sdk/package.json"), '..', 'src');
|
||||||
const jsSdkSrcDir = path.resolve(require.resolve("matrix-js-sdk/package.json"), '..', 'src');
|
const jsSdkSrcDir = path.resolve(require.resolve("matrix-js-sdk/package.json"), '..', 'src');
|
||||||
|
|
||||||
const plugins = [
|
|
||||||
// This exports our CSS using the splitChunks and loaders above.
|
|
||||||
new MiniCssExtractPlugin({
|
|
||||||
filename: 'bundles/[hash]/[name].css',
|
|
||||||
ignoreOrder: false, // Enable to remove warnings about conflicting order
|
|
||||||
}),
|
|
||||||
|
|
||||||
// This is the app's main entry point.
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
template: './src/vector/index.html',
|
|
||||||
|
|
||||||
// we inject the links ourselves via the template, because
|
|
||||||
// HtmlWebpackPlugin will screw up our formatting like the names
|
|
||||||
// of the themes and which chunks we actually care about.
|
|
||||||
inject: false,
|
|
||||||
excludeChunks: ['mobileguide', 'usercontent', 'jitsi'],
|
|
||||||
minify: argv.mode === 'production',
|
|
||||||
vars: {
|
|
||||||
og_image_url: og_image_url,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
|
|
||||||
// This is the jitsi widget wrapper (embedded, so isolated stack)
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
template: './src/vector/jitsi/index.html',
|
|
||||||
filename: 'jitsi.html',
|
|
||||||
minify: argv.mode === 'production',
|
|
||||||
chunks: ['jitsi'],
|
|
||||||
}),
|
|
||||||
|
|
||||||
// This is the mobile guide's entry point (separate for faster mobile loading)
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
template: './src/vector/mobile_guide/index.html',
|
|
||||||
filename: 'mobile_guide/index.html',
|
|
||||||
minify: argv.mode === 'production',
|
|
||||||
chunks: ['mobileguide'],
|
|
||||||
}),
|
|
||||||
|
|
||||||
// These are the static error pages for when the javascript env is *really unsupported*
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
template: './src/vector/static/unable-to-load.html',
|
|
||||||
filename: 'static/unable-to-load.html',
|
|
||||||
minify: argv.mode === 'production',
|
|
||||||
chunks: [],
|
|
||||||
}),
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
template: './src/vector/static/incompatible-browser.html',
|
|
||||||
filename: 'static/incompatible-browser.html',
|
|
||||||
minify: argv.mode === 'production',
|
|
||||||
chunks: [],
|
|
||||||
}),
|
|
||||||
|
|
||||||
// This is the usercontent sandbox's entry point (separate for iframing)
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
template: './node_modules/matrix-react-sdk/src/usercontent/index.html',
|
|
||||||
filename: 'usercontent/index.html',
|
|
||||||
minify: argv.mode === 'production',
|
|
||||||
chunks: ['usercontent'],
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
|
|
||||||
if (argv.mode === "production") {
|
|
||||||
plugins.push(new WorkboxPlugin.GenerateSW({
|
|
||||||
maximumFileSizeToCacheInBytes: 22000000,
|
|
||||||
runtimeCaching: [{
|
|
||||||
urlPattern: /i18n\/.*\.json$/,
|
|
||||||
handler: 'CacheFirst',
|
|
||||||
|
|
||||||
options: {
|
|
||||||
cacheName: 'i18n',
|
|
||||||
expiration: {
|
|
||||||
maxEntries: 2,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...development,
|
...development,
|
||||||
|
|
||||||
|
@ -226,8 +148,8 @@ module.exports = (env, argv) => {
|
||||||
},
|
},
|
||||||
loader: 'babel-loader',
|
loader: 'babel-loader',
|
||||||
options: {
|
options: {
|
||||||
cacheDirectory: true,
|
cacheDirectory: true
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
|
@ -238,7 +160,7 @@ module.exports = (env, argv) => {
|
||||||
options: {
|
options: {
|
||||||
importLoaders: 1,
|
importLoaders: 1,
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
loader: 'postcss-loader',
|
loader: 'postcss-loader',
|
||||||
|
@ -276,7 +198,7 @@ module.exports = (env, argv) => {
|
||||||
"local-plugins": true,
|
"local-plugins": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.scss$/,
|
test: /\.scss$/,
|
||||||
|
@ -287,7 +209,7 @@ module.exports = (env, argv) => {
|
||||||
options: {
|
options: {
|
||||||
importLoaders: 1,
|
importLoaders: 1,
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
loader: 'postcss-loader',
|
loader: 'postcss-loader',
|
||||||
|
@ -314,7 +236,7 @@ module.exports = (env, argv) => {
|
||||||
"local-plugins": true,
|
"local-plugins": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.wasm$/,
|
test: /\.wasm$/,
|
||||||
|
@ -372,10 +294,83 @@ module.exports = (env, argv) => {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
plugins,
|
plugins: [
|
||||||
|
// This exports our CSS using the splitChunks and loaders above.
|
||||||
|
new MiniCssExtractPlugin({
|
||||||
|
filename: 'bundles/[hash]/[name].css',
|
||||||
|
ignoreOrder: false, // Enable to remove warnings about conflicting order
|
||||||
|
}),
|
||||||
|
|
||||||
|
// This is the app's main entry point.
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: './src/vector/index.html',
|
||||||
|
|
||||||
|
// we inject the links ourselves via the template, because
|
||||||
|
// HtmlWebpackPlugin will screw up our formatting like the names
|
||||||
|
// of the themes and which chunks we actually care about.
|
||||||
|
inject: false,
|
||||||
|
excludeChunks: ['mobileguide', 'usercontent', 'jitsi'],
|
||||||
|
minify: argv.mode === 'production',
|
||||||
|
vars: {
|
||||||
|
og_image_url: og_image_url,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
|
// This is the jitsi widget wrapper (embedded, so isolated stack)
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: './src/vector/jitsi/index.html',
|
||||||
|
filename: 'jitsi.html',
|
||||||
|
minify: argv.mode === 'production',
|
||||||
|
chunks: ['jitsi'],
|
||||||
|
}),
|
||||||
|
|
||||||
|
// This is the mobile guide's entry point (separate for faster mobile loading)
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: './src/vector/mobile_guide/index.html',
|
||||||
|
filename: 'mobile_guide/index.html',
|
||||||
|
minify: argv.mode === 'production',
|
||||||
|
chunks: ['mobileguide'],
|
||||||
|
}),
|
||||||
|
|
||||||
|
// These are the static error pages for when the javascript env is *really unsupported*
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: './src/vector/static/unable-to-load.html',
|
||||||
|
filename: 'static/unable-to-load.html',
|
||||||
|
minify: argv.mode === 'production',
|
||||||
|
chunks: [],
|
||||||
|
}),
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: './src/vector/static/incompatible-browser.html',
|
||||||
|
filename: 'static/incompatible-browser.html',
|
||||||
|
minify: argv.mode === 'production',
|
||||||
|
chunks: [],
|
||||||
|
}),
|
||||||
|
|
||||||
|
// This is the usercontent sandbox's entry point (separate for iframing)
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: './node_modules/matrix-react-sdk/src/usercontent/index.html',
|
||||||
|
filename: 'usercontent/index.html',
|
||||||
|
minify: argv.mode === 'production',
|
||||||
|
chunks: ['usercontent'],
|
||||||
|
}),
|
||||||
|
|
||||||
|
new WorkboxPlugin.GenerateSW({
|
||||||
|
runtimeCaching: [{
|
||||||
|
urlPattern: /i18n\/.*\.json$/,
|
||||||
|
handler: 'CacheFirst',
|
||||||
|
|
||||||
|
options: {
|
||||||
|
cacheName: 'i18n',
|
||||||
|
expiration: {
|
||||||
|
maxEntries: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, "webapp"),
|
path: path.join(__dirname, "webapp"),
|
||||||
|
|
Loading…
Reference in New Issue