Make the version file part of webpack output (#28461)

* Make the version file part of webpack output

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Fix outputFile path for Windows compat

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2024-11-15 09:04:00 +00:00 committed by GitHub
parent e3f8a7b13d
commit d36cfc37e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 75 additions and 12 deletions

View file

@ -9,6 +9,7 @@ const TerserPlugin = require("terser-webpack-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const HtmlWebpackInjectPreload = require("@principalstudio/html-webpack-inject-preload");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const VersionFilePlugin = require("webpack-version-file-plugin");
// Environment variables
// RIOT_OG_IMAGE_URL: specifies the URL to the image which should be used for the opengraph logo.
@ -19,11 +20,6 @@ dotenv.config();
let ogImageUrl = process.env.RIOT_OG_IMAGE_URL;
if (!ogImageUrl) ogImageUrl = "https://app.element.io/themes/element/img/logos/opengraph.png";
if (!process.env.VERSION) {
console.warn("Unset VERSION variable - this may affect build output");
process.env.VERSION = "!!UNSET!!";
}
const cssThemes = {
// CSS themes
"theme-legacy-light": "./res/themes/legacy-light/css/legacy-light.pcss",
@ -97,6 +93,14 @@ module.exports = (env, argv) => {
const devMode = nodeEnv !== "production";
const enableMinification = !devMode && !process.env.CI_PACKAGE;
let VERSION = process.env.VERSION;
if (!VERSION) {
VERSION = require("./package.json").version;
if (devMode) {
VERSION += "-dev";
}
}
const development = {};
if (devMode) {
// Embedded source maps for dev builds, can't use eval-source-map due to CSP
@ -651,8 +655,6 @@ module.exports = (env, argv) => {
},
}),
new webpack.EnvironmentPlugin(["VERSION"]),
new CopyWebpackPlugin({
patterns: [
"res/apple-app-site-association",
@ -677,6 +679,15 @@ module.exports = (env, argv) => {
Buffer: ["buffer", "Buffer"],
process: "process/browser",
}),
// We bake the version in so the app knows its version immediately
new webpack.DefinePlugin({ "process.env.VERSION": JSON.stringify(VERSION) }),
// But we also write it to a file which gets polled for update detection
new VersionFilePlugin({
outputFile: "version",
templateString: "<%= extras.VERSION %>",
extras: { VERSION },
}),
].filter(Boolean),
output: {