diff --git a/frontend/gulpfile.js b/frontend/gulpfile.js index 3892e4005..b6a9af5ff 100644 --- a/frontend/gulpfile.js +++ b/frontend/gulpfile.js @@ -7,6 +7,7 @@ const sass = require("gulp-sass")(require("dart-sass")); const { task, src, dest, series, watch } = require("gulp"); const webpackDevConfig = require("./webpack/config.dev.js"); const webpackProdConfig = require("./webpack/config.prod.js"); +const webpackActionConfig = require("./webpack/config.action.js"); const JSONValidation = require("./scripts/json-validation"); const eslintConfig = "../.eslintrc.json"; @@ -56,6 +57,7 @@ const taskWithWebpackConfig = (webpackConfig) => { task("webpack", taskWithWebpackConfig(webpackDevConfig)); task("webpack-production", taskWithWebpackConfig(webpackProdConfig)); +task("webpack-action", taskWithWebpackConfig(webpackActionConfig)); task("sass", function () { return src("./src/styles/*.scss") @@ -117,4 +119,4 @@ task("pr-check-other-json", series("validate-other-json-schema")); task("pr-check-lint", series("lint")); task("pr-check-scss", series("sass")); -task("pr-check-ts", series("webpack-production")); +task("pr-check-ts", series("webpack-action")); diff --git a/frontend/webpack/config.action.js b/frontend/webpack/config.action.js new file mode 100644 index 000000000..94bb0a1bc --- /dev/null +++ b/frontend/webpack/config.action.js @@ -0,0 +1,63 @@ +const { merge } = require("webpack-merge"); +const HtmlMinimizerPlugin = require("html-minimizer-webpack-plugin"); + +const BASE_CONFIGURATION = require("./config.base"); + +function pad(numbers, maxLength, fillString) { + return numbers.map((number) => + number.toString().padStart(maxLength, fillString) + ); +} + +const ACTION_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()], + }, +}; + +module.exports = merge(BASE_CONFIGURATION, ACTION_CONFIGURATION);