2020-03-27 20:59:38 +00:00
|
|
|
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
2020-04-26 17:49:20 +00:00
|
|
|
console.log('Running in production mode'); // eslint-disable-line no-console
|
2020-03-27 20:59:38 +00:00
|
|
|
|
2021-09-12 15:51:58 +00:00
|
|
|
const { join } = require('path');
|
2020-10-07 21:33:56 +00:00
|
|
|
const { merge } = require('webpack-merge');
|
2020-03-27 20:59:38 +00:00
|
|
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
2021-09-05 21:42:48 +00:00
|
|
|
const OfflinePlugin = require('@lcdp/offline-plugin');
|
2020-03-27 20:59:38 +00:00
|
|
|
const sharedConfig = require('./shared');
|
|
|
|
|
2021-09-12 15:51:58 +00:00
|
|
|
const { FE_SUBDIRECTORY } = require(join(__dirname, '..', 'app', 'soapbox', 'build_config'));
|
|
|
|
const joinPublicPath = (...paths) => join(FE_SUBDIRECTORY, ...paths);
|
|
|
|
|
2021-09-05 21:42:48 +00:00
|
|
|
module.exports = merge(sharedConfig, {
|
2020-03-27 20:59:38 +00:00
|
|
|
mode: 'production',
|
|
|
|
devtool: 'source-map',
|
2021-09-04 21:05:20 +00:00
|
|
|
stats: 'errors-warnings',
|
2020-03-27 20:59:38 +00:00
|
|
|
bail: true,
|
|
|
|
optimization: {
|
|
|
|
minimize: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
2021-09-05 21:42:48 +00:00
|
|
|
// Generates report.html
|
|
|
|
new BundleAnalyzerPlugin({
|
2020-03-27 20:59:38 +00:00
|
|
|
analyzerMode: 'static',
|
|
|
|
openAnalyzer: false,
|
2021-09-05 21:42:48 +00:00
|
|
|
logLevel: 'silent',
|
2020-03-27 20:59:38 +00:00
|
|
|
}),
|
|
|
|
new OfflinePlugin({
|
|
|
|
caches: {
|
|
|
|
main: [':rest:'],
|
2021-09-11 01:11:36 +00:00
|
|
|
additional: [
|
2021-09-12 15:51:58 +00:00
|
|
|
':externals:',
|
|
|
|
'packs/images/32-*.png', // used in emoji-mart
|
2021-09-27 01:00:16 +00:00
|
|
|
'packs/icons/*.svg',
|
2021-09-11 01:11:36 +00:00
|
|
|
],
|
2020-03-27 20:59:38 +00:00
|
|
|
optional: [
|
|
|
|
'**/locale_*.js', // don't fetch every locale; the user only needs one
|
|
|
|
'**/*_polyfills-*.js', // the user may not need polyfills
|
2021-07-23 01:06:18 +00:00
|
|
|
'**/*.chunk.js', // only cache chunks when needed
|
2021-09-12 15:51:58 +00:00
|
|
|
'**/*.chunk.css',
|
2020-03-27 20:59:38 +00:00
|
|
|
'**/*.woff2', // the user may have system-fonts enabled
|
2021-09-10 22:43:35 +00:00
|
|
|
// images can be cached on-demand
|
2020-03-27 20:59:38 +00:00
|
|
|
'**/*.png',
|
|
|
|
'**/*.svg',
|
|
|
|
],
|
|
|
|
},
|
2021-09-12 15:51:58 +00:00
|
|
|
externals: [
|
|
|
|
joinPublicPath('packs/emoji/1f602.svg'), // used for emoji picker dropdown
|
|
|
|
|
|
|
|
// Default emoji reacts
|
|
|
|
joinPublicPath('packs/emoji/1f44d.svg'), // Thumbs up
|
|
|
|
joinPublicPath('packs/emoji/2764.svg'), // Heart
|
|
|
|
joinPublicPath('packs/emoji/1f606.svg'), // Laughing
|
|
|
|
joinPublicPath('packs/emoji/1f62e.svg'), // Surprised
|
|
|
|
joinPublicPath('packs/emoji/1f622.svg'), // Crying
|
|
|
|
joinPublicPath('packs/emoji/1f629.svg'), // Weary
|
|
|
|
joinPublicPath('packs/emoji/1f621.svg'), // Angry (Spinster)
|
|
|
|
],
|
2020-03-27 20:59:38 +00:00
|
|
|
excludes: [
|
|
|
|
'**/*.gz',
|
|
|
|
'**/*.map',
|
2021-09-11 01:11:36 +00:00
|
|
|
'**/*.LICENSE.txt',
|
2020-03-27 20:59:38 +00:00
|
|
|
'stats.json',
|
|
|
|
'report.html',
|
2021-09-08 15:57:58 +00:00
|
|
|
'instance/**/*',
|
2020-03-27 20:59:38 +00:00
|
|
|
// any browser that supports ServiceWorker will support woff2
|
|
|
|
'**/*.eot',
|
|
|
|
'**/*.ttf',
|
|
|
|
'**/*-webfont-*.svg',
|
|
|
|
'**/*.woff',
|
2021-09-07 00:20:47 +00:00
|
|
|
// Sounds return a 206 causing sw.js to crash
|
|
|
|
// https://stackoverflow.com/a/66335638
|
2021-09-10 22:43:35 +00:00
|
|
|
'**/*.ogg',
|
|
|
|
'**/*.oga',
|
|
|
|
'**/*.mp3',
|
2021-09-11 01:11:36 +00:00
|
|
|
'404.html',
|
2021-09-12 15:51:58 +00:00
|
|
|
'assets-manifest.json',
|
|
|
|
// It would be nice to serve these, but they bloat up sw.js
|
|
|
|
'packs/images/crypto/**/*',
|
|
|
|
'packs/emoji/**/*',
|
2020-03-27 20:59:38 +00:00
|
|
|
],
|
2021-09-12 15:51:58 +00:00
|
|
|
ServiceWorker: {
|
2021-10-21 03:07:48 +00:00
|
|
|
cacheName: 'soapbox',
|
2021-10-21 20:31:09 +00:00
|
|
|
entry: join(__dirname, '../app/soapbox/service_worker/entry.js'),
|
2021-09-12 15:51:58 +00:00
|
|
|
minify: true,
|
|
|
|
},
|
2021-10-21 03:07:48 +00:00
|
|
|
cacheMaps: [{
|
|
|
|
match: requestUrl => {
|
|
|
|
const backendRoutes = [
|
|
|
|
'/api',
|
|
|
|
'/pleroma',
|
|
|
|
'/nodeinfo',
|
|
|
|
'/socket',
|
|
|
|
'/oauth',
|
|
|
|
'/auth/password',
|
|
|
|
'/.well-known/webfinger',
|
|
|
|
'/static',
|
2021-10-21 17:22:20 +00:00
|
|
|
'/instance',
|
2021-10-21 03:07:48 +00:00
|
|
|
'/main/ostatus',
|
|
|
|
'/ostatus_subscribe',
|
|
|
|
'/pghero',
|
|
|
|
'/sidekiq',
|
|
|
|
];
|
|
|
|
|
|
|
|
const isBackendRoute = ({ pathname }) => {
|
2021-11-15 19:03:30 +00:00
|
|
|
if (pathname) {
|
|
|
|
return backendRoutes.some(pathname.startsWith);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2021-10-21 03:07:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return isBackendRoute(requestUrl) && requestUrl;
|
|
|
|
},
|
|
|
|
requestTypes: ['navigate'],
|
|
|
|
}],
|
2021-09-11 00:39:39 +00:00
|
|
|
safeToUseOptionalCaches: true,
|
2021-10-20 22:07:10 +00:00
|
|
|
appShell: join(FE_SUBDIRECTORY, '/'),
|
2020-03-27 20:59:38 +00:00
|
|
|
}),
|
|
|
|
],
|
2021-09-05 21:42:48 +00:00
|
|
|
});
|