2017-05-03 02:04:16 +02:00
|
|
|
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
|
|
|
|
2022-08-25 20:10:01 +02:00
|
|
|
const { createHash } = require('crypto');
|
|
|
|
const { readFileSync } = require('fs');
|
|
|
|
const { resolve } = require('path');
|
2023-05-23 17:15:17 +02:00
|
|
|
|
2017-05-20 17:31:47 +02:00
|
|
|
const CompressionPlugin = require('compression-webpack-plugin');
|
2023-05-23 17:15:17 +02:00
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
|
|
|
const { merge } = require('webpack-merge');
|
2022-08-25 20:10:01 +02:00
|
|
|
const { InjectManifest } = require('workbox-webpack-plugin');
|
2023-05-23 17:15:17 +02:00
|
|
|
|
2019-03-15 15:05:31 +01:00
|
|
|
const sharedConfig = require('./shared');
|
2017-05-03 02:04:16 +02:00
|
|
|
|
2022-08-25 20:10:01 +02:00
|
|
|
const root = resolve(__dirname, '..', '..');
|
2018-05-29 00:43:47 +02:00
|
|
|
|
2017-05-03 02:04:16 +02:00
|
|
|
module.exports = merge(sharedConfig, {
|
2018-07-14 03:56:41 +02:00
|
|
|
mode: 'production',
|
2019-03-15 15:05:31 +01:00
|
|
|
devtool: 'source-map',
|
2017-06-18 02:57:09 +02:00
|
|
|
stats: 'normal',
|
2019-03-15 15:05:31 +01:00
|
|
|
bail: true,
|
2018-07-14 03:56:41 +02:00
|
|
|
optimization: {
|
|
|
|
minimize: true,
|
|
|
|
minimizer: [
|
2019-06-04 14:17:09 +02:00
|
|
|
new TerserPlugin({
|
2018-10-06 08:12:05 +02:00
|
|
|
cache: true,
|
|
|
|
parallel: true,
|
2018-07-14 03:56:41 +02:00
|
|
|
sourceMap: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
2017-05-03 02:04:16 +02:00
|
|
|
new CompressionPlugin({
|
2021-06-25 04:45:04 +02:00
|
|
|
filename: '[path][base].gz[query]',
|
2019-03-15 15:05:31 +01:00
|
|
|
cache: true,
|
|
|
|
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/,
|
2022-12-15 17:07:36 +01:00
|
|
|
}),
|
|
|
|
new CompressionPlugin({
|
|
|
|
filename: '[path][base].br[query]',
|
|
|
|
algorithm: 'brotliCompress',
|
|
|
|
cache: true,
|
|
|
|
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/,
|
2017-05-20 17:31:47 +02:00
|
|
|
}),
|
2019-03-16 11:23:54 +01:00
|
|
|
new BundleAnalyzerPlugin({ // generates report.html
|
2017-05-22 15:42:11 +02:00
|
|
|
analyzerMode: 'static',
|
|
|
|
openAnalyzer: false,
|
2017-05-28 16:26:16 +02:00
|
|
|
logLevel: 'silent', // do not bother Webpacker, who runs with --json and parses stdout
|
2017-05-22 15:42:11 +02:00
|
|
|
}),
|
2022-08-25 20:10:01 +02:00
|
|
|
new InjectManifest({
|
|
|
|
additionalManifestEntries: ['1f602.svg', 'sheet_13.png'].map((filename) => {
|
|
|
|
const path = resolve(root, 'public', 'emoji', filename);
|
|
|
|
const body = readFileSync(path);
|
|
|
|
const md5 = createHash('md5');
|
|
|
|
|
|
|
|
md5.update(body);
|
|
|
|
|
|
|
|
return {
|
|
|
|
revision: md5.digest('hex'),
|
|
|
|
url: `/emoji/${filename}`,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
exclude: [
|
|
|
|
/(?:base|extra)_polyfills-.*\.js$/,
|
|
|
|
/locale_.*\.js$/,
|
|
|
|
/mailer-.*\.(?:css|js)$/,
|
2017-10-31 12:25:51 +01:00
|
|
|
],
|
2022-08-25 20:10:01 +02:00
|
|
|
include: [/\.js$/, /\.css$/],
|
|
|
|
maximumFileSizeToCacheInBytes: 2 * 1_024 * 1_024, // 2 MiB
|
|
|
|
swDest: resolve(root, 'public', 'packs', 'sw.js'),
|
|
|
|
swSrc: resolve(root, 'app', 'javascript', 'mastodon', 'service_worker', 'entry.js'),
|
2017-07-13 22:15:32 +02:00
|
|
|
}),
|
2017-05-20 17:31:47 +02:00
|
|
|
],
|
|
|
|
});
|