added action webpack config

This commit is contained in:
Miodec 2022-03-18 01:37:36 +01:00
parent 4d44fe6c00
commit 0a1e5e1660
2 changed files with 66 additions and 1 deletions

View file

@ -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"));

View file

@ -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);