1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
# Copyright 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("../../../scripts/build/typescript/typescript.gni")
import("./node.gni")
import("./vars.gni")
declare_args() {
# If this is enabled, devtools build uses esbuild instead of rollup.js to
# bundle JavaScript files.
devtools_fast_bundle = devtools_skip_typecheck
# If this is enabled, we will emit source maps for the entrypoint bundles.
# Since we only bundle release builds, this flag can't be used with
# is_debug = true.
# Note that this flag works regardless of the devtools_skip_typecheck or
# devtools_fast_bundle GN arg. Both rollup.js or ESBuild will emit source
# maps if this flag is set.
devtools_release_sourcemaps = false
}
assert(!(devtools_fast_bundle && is_official_build),
"Official build should not bundle with esbuild")
# Release source map implies release build.
assert(!devtools_release_sourcemaps || !is_debug,
"Release source maps can only be enabled for release builds")
template("bundle") {
assert(defined(invoker.entrypoint),
"You must define the 'entrypoint' for a bundle target")
if (devtools_fast_bundle) {
node_action(target_name) {
script = "scripts/build/esbuild.js"
forward_variables_from(invoker,
[
"visibility",
"deps",
"public_deps",
])
inputs = [
invoker.entrypoint,
devtools_location_prepend + "scripts/build/devtools_plugin.js",
devtools_location_prepend + "scripts/devtools_paths.js",
]
_esbuild = devtools_location_prepend + "third_party/esbuild/esbuild"
if (host_os == "win") {
inputs += [ _esbuild + ".exe" ]
} else {
inputs += [ _esbuild ]
}
args = [
rebase_path(invoker.entrypoint, root_build_dir),
rebase_path(invoker.output_file_location, root_build_dir),
]
if (devtools_release_sourcemaps) {
args += [ "--configSourcemaps" ]
}
outputs = [ invoker.output_file_location ]
}
} else {
node_action(target_name) {
script = "node_modules/rollup3/dist/bin/rollup"
forward_variables_from(invoker,
[
"visibility",
"deps",
"public_deps",
])
inputs = [
invoker.entrypoint,
devtools_location_prepend + "scripts/build/rollup.config.mjs",
devtools_location_prepend + "scripts/build/devtools_plugin.js",
devtools_location_prepend + "scripts/devtools_paths.js",
]
args = [
# TODO(crbug.com/1098074): We need to hide warnings that are written stderr,
# as Chromium does not process the returncode of the subprocess correctly
# and instead looks if `stderr` is empty.
"--silent",
"--config",
rebase_path(
devtools_location_prepend + "scripts/build/rollup.config.mjs",
root_build_dir),
"--input",
rebase_path(invoker.entrypoint, root_build_dir),
"--file",
rebase_path(invoker.output_file_location, root_build_dir),
]
if (devtools_release_sourcemaps) {
args += [ "--configSourcemaps" ]
}
outputs = [ invoker.output_file_location ]
}
}
}
|