bigbuffet-rw/webpack/production.js

136 lines
4.1 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
// Note: You must restart bin/webpack-dev-server for changes to take effect
console.log('Running in production mode'); // eslint-disable-line no-console
2020-03-27 13:59:38 -07:00
2022-04-05 12:43:29 -07:00
const { join } = require('path');
2022-04-05 12:43:29 -07:00
const OfflinePlugin = require('@lcdp/offline-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { merge } = require('webpack-merge');
2020-03-27 13:59:38 -07:00
const sharedConfig = require('./shared');
2022-04-05 12:43:29 -07:00
const { FE_SUBDIRECTORY } = require(join(__dirname, '..', 'app', 'soapbox', 'build_config'));
const joinPublicPath = (...paths) => join(FE_SUBDIRECTORY, ...paths);
2021-09-05 14:42:48 -07:00
module.exports = merge(sharedConfig, {
2020-03-27 13:59:38 -07:00
mode: 'production',
devtool: 'source-map',
2021-09-04 14:05:20 -07:00
stats: 'errors-warnings',
2020-03-27 13:59:38 -07:00
bail: true,
optimization: {
minimize: true,
},
plugins: [
2021-09-05 14:42:48 -07:00
// Generates report.html
new BundleAnalyzerPlugin({
2020-03-27 13:59:38 -07:00
analyzerMode: 'static',
openAnalyzer: false,
2021-09-05 14:42:48 -07:00
logLevel: 'silent',
2020-03-27 13:59:38 -07:00
}),
2022-04-05 12:43:29 -07:00
new OfflinePlugin({
2022-06-28 13:04:38 -07:00
autoUpdate: true,
2022-04-05 12:43:29 -07:00
caches: {
main: [':rest:'],
additional: [
':externals:',
'packs/images/32-*.png', // used in emoji-mart
'packs/icons/*.svg',
],
optional: [
'**/locale_*.js', // don't fetch every locale; the user only needs one
'**/*_polyfills-*.js', // the user may not need polyfills
'**/*.chunk.js', // only cache chunks when needed
'**/*.chunk.css',
'**/*.woff2', // the user may have system-fonts enabled
// images can be cached on-demand
'**/*.png',
'**/*.svg',
],
},
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)
],
excludes: [
'**/*.gz',
'**/*.map',
'**/*.LICENSE.txt',
'stats.json',
'report.html',
'instance/**/*',
// any browser that supports ServiceWorker will support woff2
'**/*.eot',
'**/*.ttf',
'**/*-webfont-*.svg',
'**/*.woff',
// Sounds return a 206 causing sw.js to crash
// https://stackoverflow.com/a/66335638
'**/*.ogg',
'**/*.oga',
'**/*.mp3',
'404.html',
'assets-manifest.json',
// It would be nice to serve these, but they bloat up sw.js
'packs/images/crypto/**/*',
'packs/emoji/**/*',
],
ServiceWorker: {
cacheName: 'soapbox',
2022-05-26 11:51:59 -07:00
entry: join(__dirname, '../app/soapbox/service_worker/entry.ts'),
events: true,
2022-04-05 12:43:29 -07:00
minify: true,
},
cacheMaps: [{
// NOTE: This function gets stringified by OfflinePlugin, so don't try
// moving it anywhere else or making it depend on anything outside it!
// https://github.com/NekR/offline-plugin/blob/master/docs/cache-maps.md
match: (url) => {
const { pathname } = url;
2022-04-05 12:43:29 -07:00
const backendRoutes = [
'/.well-known',
2022-06-29 10:29:51 -07:00
'/activities',
'/admin',
2022-04-05 12:43:29 -07:00
'/api',
'/auth',
2022-06-29 10:29:51 -07:00
'/inbox',
2022-04-05 12:43:29 -07:00
'/instance',
2022-06-29 10:29:51 -07:00
'/internal',
2022-04-05 12:43:29 -07:00
'/main/ostatus',
'/manifest.json',
'/media',
'/nodeinfo',
'/oauth',
2022-06-29 10:29:51 -07:00
'/objects',
2022-04-05 12:43:29 -07:00
'/ostatus_subscribe',
'/pghero',
'/pleroma',
2022-06-29 10:29:51 -07:00
'/proxy',
'/relay',
2022-04-05 12:43:29 -07:00
'/sidekiq',
'/socket',
'/static',
'/unsubscribe',
2022-04-05 12:43:29 -07:00
];
if (backendRoutes.some(path => pathname.startsWith(path)) || pathname.endsWith('/embed')) {
return url;
}
2022-04-05 12:43:29 -07:00
},
requestTypes: ['navigate'],
}],
safeToUseOptionalCaches: true,
appShell: join(FE_SUBDIRECTORY, '/'),
}),
2020-03-27 13:59:38 -07:00
],
2021-09-05 14:42:48 -07:00
});