~cytrogen/masto-fe

masto-fe/config/webpack/production.js -rw-r--r-- 2.2 KiB
f8dc013b — Cytrogen [feature] Add language selector to local settings 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Note: You must restart bin/webpack-dev-server for changes to take effect

const { createHash } = require("crypto");
const { readFileSync } = require("fs");
const { resolve } = require("path");

const CompressionPlugin = require("@renchap/compression-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const { merge } = require("webpack-merge");
const { InjectManifest } = require("workbox-webpack-plugin");

const sharedConfig = require("./shared");

const root = resolve(__dirname, "..", "..");

module.exports = merge(sharedConfig, {
  mode: "production",
  devtool: "source-map",
  stats: "normal",
  bail: true,
  optimization: {
    minimize: true,
    minimizer: [
      new TerserPlugin({
        parallel: true,
      }),
    ],
  },

  plugins: [
    new CompressionPlugin({
      filename: "[path][base].gz[query]",
      cache: true,
      test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/,
    }),
    new CompressionPlugin({
      filename: "[path][base].br[query]",
      algorithm: "brotliCompress",
      cache: true,
      test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/,
    }),
    new BundleAnalyzerPlugin({ // generates report.html
      analyzerMode: "static",
      openAnalyzer: false,
      logLevel: "silent", // do not bother Webpacker, who runs with --json and parses stdout
    }),
    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)$/,
      ],
      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"),
    }),
  ],
});