From fc2b29cf2ec0a123aa704a4a3152b6e414243e15 Mon Sep 17 00:00:00 2001 From: Jean Honlet <21492958-jeanhonlet@users.noreply.gitlab.com> Date: Thu, 27 Feb 2025 09:02:53 +0100 Subject: [PATCH] build: do more in webpack --- Makefile | 7 +------ Makefile-frontend | 1 + Makefile-integration | 9 +-------- webpack.config.js | 30 +++++++++++++++++++++++++++--- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 73ba06d21..0a9e0e1d9 100644 --- a/Makefile +++ b/Makefile @@ -107,7 +107,7 @@ clean-files: rm -f "$(ROOT)/.ovhconfig" rm -f "$(ROOT)/www/built/backup" - rm -f "$(ROOT)/www/built/browsers.json" + dc-build: docker compose build @@ -194,7 +194,6 @@ $(HOME)/.ssh/id_rsa: .PHONY: build build: \ www/built/backup \ - www/built/release_version.txt \ .ovhconfig .ovhconfig: conf/ovhconfig .env @@ -205,10 +204,6 @@ www/built/backup: bin/cr-live-backup.sh @mkdir -p "$(dir $@)" cp -f "$<" "$@" -www/built/release_version.txt: - @mkdir -p "$(dir $@)" - date > "$@" - .PHONY: update-references-browsers update: update-references-browsers update-references-browsers: diff --git a/Makefile-frontend b/Makefile-frontend index 8184dacb5..8c82764c7 100644 --- a/Makefile-frontend +++ b/Makefile-frontend @@ -90,6 +90,7 @@ $(FRONTEND_PUBLISHED)/frontend/ng1x.html: \ $(shell find src/ ) \ $(shell find legacy/app-old/ ) \ src/build.htaccess \ + .browserslistrc \ webpack.config.js \ tsconfig.json diff --git a/Makefile-integration b/Makefile-integration index 95307b9c0..eacc24a2b 100644 --- a/Makefile-integration +++ b/Makefile-integration @@ -46,18 +46,11 @@ integration-build: $(INTEGRATION_BUILT_MARK) $(INTEGRATION_BUILT_MARK): \ $(BACKEND_BUILT_MARK) \ - $(FRONTEND_BUILT_MARK) \ - www/built/browsers.json + $(FRONTEND_BUILT_MARK) @mkdir -p "$(dir $@)" @touch "$@" -www/built/browsers.json: .browserslistrc $(FRONTEND_DEPENDENCIES_MARK) - @mkdir -p "$(dir $@)" -# pipe will not work with snap - node_modules/.bin/browserslist --json | tee "$@" - @touch "$@" - .PHONY: integration-test test: integration-test integration-test: integration-test-desktop integration-test-playwright diff --git a/webpack.config.js b/webpack.config.js index 9cb4b517f..2eaaaf27b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,8 @@ /* eslint-env node */ +import browserslist from "browserslist"; import HtmlWebpackPlugin from "html-webpack-plugin"; +import child_process from "node:child_process"; import fs from "node:fs"; import path from "node:path"; import url from "node:url"; @@ -8,14 +10,36 @@ import url from "node:url"; const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); const webRoot = path.join(__dirname, "/www/"); -const webBuildRoot = "/built/frontend"; -const builtRoot = path.join(webRoot, webBuildRoot); +const frontendRoot = path.join(webRoot, "/built"); +// TODO: flattern this a bit +const webBuildRoot = "/frontend"; +const builtRoot = path.join(frontendRoot, webBuildRoot); fs.rmSync(builtRoot, { force: true, recursive: true }); fs.mkdirSync(builtRoot, { recursive: true }); fs.copyFileSync( path.join(__dirname, "src/build.htaccess"), - path.join(webRoot, "built", ".htaccess") + path.join(frontendRoot, ".htaccess") +); + +const browsers = browserslist(); +fs.writeFileSync( + path.join(frontendRoot, "browsers.json"), + JSON.stringify(browsers) +); + +fs.writeFileSync( + path.join(frontendRoot, "release_version.txt"), + JSON.stringify( + { + date: new Date().toISOString(), + git: child_process + .execSync("git rev-parse HEAD", { encoding: "UTF8" }) + .trim() + }, + null, + 2 + ) ); const isDebug = process.env.CRYPTOMEDIC_DEV ?? false;