diff --git a/esbuild/esbuild.js b/esbuild/esbuild.js index b288b4e495..5f5f805c1a 100644 --- a/esbuild/esbuild.js +++ b/esbuild/esbuild.js @@ -68,6 +68,10 @@ const argv = yargs description: "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 --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 PRODUCTION = Boolean(argv.production); 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 NODE_PATHS = [].concat( @@ -313,7 +318,7 @@ function get_build_options(files, outdir, plugins) { return { entryPoints: files, entryNames: "[dir]/[name].[hash]", - target: ["es2017"], + target: [ESBUILD_TARGET], outdir, sourcemap: true, bundle: true, diff --git a/frappe/build.py b/frappe/build.py index 83fe189ba6..98fbce515b 100644 --- a/frappe/build.py +++ b/frappe/build.py @@ -228,6 +228,7 @@ def bundle( files=None, save_metafiles=False, using_cached=False, + esbuild_target=None, ): """concat / minify js files""" setup() @@ -239,6 +240,9 @@ def bundle( if apps: command += f" --apps {apps}" + if esbuild_target: + command += f" --esbuild-target {esbuild_target}" + if skip_frappe: command += " --skip_frappe" diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index afafadcbaf..faafcdc5d3 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -78,6 +78,8 @@ def build( # don't minify in developer_mode for faster builds 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" if production: mode = "production" @@ -93,6 +95,7 @@ def build( skip_frappe=skip_frappe, save_metafiles=save_metafiles, using_cached=using_cached, + esbuild_target=esbuild_target, ) if apps and isinstance(apps, str):