monkeytype/frontend/webpack/config.prod.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

const { merge } = require("webpack-merge");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const HtmlMinimizerPlugin = require("html-minimizer-webpack-plugin");
const JsonMinimizerPlugin = require("json-minimizer-webpack-plugin");
const BASE_CONFIGURATION = require("./config.base");
function pad(numbers, maxLength, fillString) {
return numbers.map((number) =>
number.toString().padStart(maxLength, fillString)
);
}
const PRODUCTION_CONFIGURATION = {
mode: "production",
module: {
rules: [
{
test: /version\.ts$/,
loader: "string-replace-loader",
options: {
search: /^export const CLIENT_VERSION =.*/,
replace(_match, _p1, _offset, _string) {
const date = new Date();
const versionPrefix = pad(
[date.getFullYear(), date.getMonth() + 1, date.getDate()],
2,
"0"
).join(".");
const versionSuffix = pad(
[date.getHours(), date.getMinutes()],
2,
"0"
).join(".");
const version = [versionPrefix, versionSuffix].join("_");
return `export const CLIENT_VERSION = "${version}";`;
},
flags: "g",
},
},
{
test: /\.m?js$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
plugins: [
"@babel/plugin-transform-runtime",
"@babel/plugin-transform-modules-commonjs",
],
},
},
},
],
},
optimization: {
minimize: true,
minimizer: [
`...`,
new HtmlMinimizerPlugin(),
new JsonMinimizerPlugin(),
new CssMinimizerPlugin(),
],
},
};
module.exports = merge(BASE_CONFIGURATION, PRODUCTION_CONFIGURATION);