webpack: Build a ZULIP_VERSION global constant into the built product.

This commit is contained in:
Alex Vandiver 2023-03-03 21:38:01 +00:00 committed by Tim Abbott
parent 73631950a5
commit a8181152b7
4 changed files with 24 additions and 2 deletions

View File

@ -237,6 +237,9 @@
"browser": true,
"node": false
},
"globals": {
"ZULIP_VERSION": false
},
"rules": {
"no-console": "error"
},

View File

@ -3,11 +3,17 @@ import argparse
import json
import os
import subprocess
import sys
from typing import NoReturn
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
os.chdir(os.path.join(os.path.dirname(__file__), "../web"))
from version import ZULIP_VERSION
def build_for_prod_or_puppeteer(quiet: bool) -> NoReturn:
"""Builds for production, writing the output to disk"""
@ -15,7 +21,11 @@ def build_for_prod_or_puppeteer(quiet: bool) -> NoReturn:
with open("/proc/meminfo") as meminfo:
if int(next(meminfo).split()[1]) < 3 * 1024 * 1024:
webpack_args += ["--max-old-space-size=1536"]
webpack_args += ["../node_modules/.bin/webpack-cli", "--mode=production"]
webpack_args += [
"../node_modules/.bin/webpack-cli",
"--mode=production",
f"--env=ZULIP_VERSION={ZULIP_VERSION}",
]
if quiet:
webpack_args += ["--stats=errors-only"]
os.execvp(webpack_args[0], webpack_args)

2
web/src/global.d.ts vendored
View File

@ -9,3 +9,5 @@ interface JQuery {
expectOne(): JQuery;
tab(action?: string): this; // From web/third/bootstrap
}
declare const ZULIP_VERSION: string;

View File

@ -5,6 +5,7 @@ import path from "path";
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import {DefinePlugin} from "webpack";
import type webpack from "webpack";
import BundleTracker from "webpack-bundle-tracker";
@ -12,7 +13,10 @@ import DebugRequirePlugin from "./debug-require-webpack-plugin";
import assets from "./webpack.assets.json";
import dev_assets from "./webpack.dev-assets.json";
export default (env: {minimize?: boolean} = {}, argv: {mode?: string}): webpack.Configuration[] => {
export default (
env: {minimize?: boolean; ZULIP_VERSION?: string} = {},
argv: {mode?: string},
): webpack.Configuration[] => {
const production: boolean = argv.mode === "production";
const baseConfig: webpack.Configuration = {
@ -194,6 +198,9 @@ export default (env: {minimize?: boolean} = {}, argv: {mode?: string}): webpack.
},
},
plugins: [
new DefinePlugin({
ZULIP_VERSION: JSON.stringify(env.ZULIP_VERSION || "development"),
}),
new DebugRequirePlugin(),
new BundleTracker({
filename: production