feat: configurable esbuild build target (#34398)

This commit is contained in:
Samar Singh 2025-10-17 06:25:21 +05:30 committed by GitHub
parent 871ae70172
commit 39b14f3a67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 1 deletions

View file

@ -68,6 +68,10 @@ const argv = yargs
description: description:
"Skips build and uses cached build artifacts to update assets.json (used by Bench)", "Skips build and uses cached build artifacts to update assets.json (used by Bench)",
}) })
.option("esbuild-target", {
type: "string",
description: "Specifies the target of the build output.",
})
.example("node esbuild --apps frappe,erpnext", "Run build only for frappe and erpnext") .example("node esbuild --apps frappe,erpnext", "Run build only for frappe and erpnext")
.example( .example(
"node esbuild --files frappe/website.bundle.js,frappe/desk.bundle.js", "node esbuild --files frappe/website.bundle.js,frappe/desk.bundle.js",
@ -82,6 +86,7 @@ const FILES_TO_BUILD = argv.files ? argv.files.split(",") : [];
const WATCH_MODE = Boolean(argv.watch); const WATCH_MODE = Boolean(argv.watch);
const PRODUCTION = Boolean(argv.production); const PRODUCTION = Boolean(argv.production);
const RUN_BUILD_COMMAND = !WATCH_MODE && Boolean(argv["run-build-command"]); const RUN_BUILD_COMMAND = !WATCH_MODE && Boolean(argv["run-build-command"]);
const ESBUILD_TARGET = argv["esbuild-target"] || "es2017";
const TOTAL_BUILD_TIME = `${chalk.black.bgGreen(" DONE ")} Total Build Time`; const TOTAL_BUILD_TIME = `${chalk.black.bgGreen(" DONE ")} Total Build Time`;
const NODE_PATHS = [].concat( const NODE_PATHS = [].concat(
@ -313,7 +318,7 @@ function get_build_options(files, outdir, plugins) {
return { return {
entryPoints: files, entryPoints: files,
entryNames: "[dir]/[name].[hash]", entryNames: "[dir]/[name].[hash]",
target: ["es2017"], target: [ESBUILD_TARGET],
outdir, outdir,
sourcemap: true, sourcemap: true,
bundle: true, bundle: true,

View file

@ -228,6 +228,7 @@ def bundle(
files=None, files=None,
save_metafiles=False, save_metafiles=False,
using_cached=False, using_cached=False,
esbuild_target=None,
): ):
"""concat / minify js files""" """concat / minify js files"""
setup() setup()
@ -239,6 +240,9 @@ def bundle(
if apps: if apps:
command += f" --apps {apps}" command += f" --apps {apps}"
if esbuild_target:
command += f" --esbuild-target {esbuild_target}"
if skip_frappe: if skip_frappe:
command += " --skip_frappe" command += " --skip_frappe"

View file

@ -78,6 +78,8 @@ def build(
# don't minify in developer_mode for faster builds # don't minify in developer_mode for faster builds
development = frappe.local.conf.developer_mode or frappe._dev_server development = frappe.local.conf.developer_mode or frappe._dev_server
esbuild_target = frappe.local.conf.get("esbuild_target") or os.environ.get("ESBUILD_TARGET")
mode = "development" if development else "production" mode = "development" if development else "production"
if production: if production:
mode = "production" mode = "production"
@ -93,6 +95,7 @@ def build(
skip_frappe=skip_frappe, skip_frappe=skip_frappe,
save_metafiles=save_metafiles, save_metafiles=save_metafiles,
using_cached=using_cached, using_cached=using_cached,
esbuild_target=esbuild_target,
) )
if apps and isinstance(apps, str): if apps and isinstance(apps, str):