2022-03-17 03:57:30 +08:00
|
|
|
const { merge } = require("webpack-merge");
|
2022-03-18 22:40:40 +08:00
|
|
|
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
2022-03-18 04:00:20 +08:00
|
|
|
const HtmlMinimizerPlugin = require("html-minimizer-webpack-plugin");
|
2022-03-18 22:40:40 +08:00
|
|
|
const JsonMinimizerPlugin = require("json-minimizer-webpack-plugin");
|
2022-03-18 04:00:20 +08:00
|
|
|
|
2022-03-17 03:57:30 +08:00
|
|
|
const BASE_CONFIGURATION = require("./config.base");
|
|
|
|
|
2022-03-17 07:18:29 +08:00
|
|
|
function pad(numbers, maxLength, fillString) {
|
|
|
|
return numbers.map((number) =>
|
|
|
|
number.toString().padStart(maxLength, fillString)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-03-17 03:57:30 +08:00
|
|
|
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();
|
2022-03-17 07:18:29 +08:00
|
|
|
|
|
|
|
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}";`;
|
2022-03-17 03:57:30 +08:00
|
|
|
},
|
|
|
|
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",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2022-03-18 04:00:20 +08:00
|
|
|
optimization: {
|
|
|
|
minimize: true,
|
2022-03-18 22:40:40 +08:00
|
|
|
minimizer: [
|
|
|
|
`...`,
|
|
|
|
new HtmlMinimizerPlugin(),
|
|
|
|
new JsonMinimizerPlugin(),
|
|
|
|
new CssMinimizerPlugin(),
|
|
|
|
],
|
2022-03-18 04:00:20 +08:00
|
|
|
},
|
2022-03-17 03:57:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = merge(BASE_CONFIGURATION, PRODUCTION_CONFIGURATION);
|