Question: Post initial builds in bazel are greater than 10seconds, is this normal? How can I reduce the build times of Bazel with my example below?
Commands:
yarn
npx bazel build :bundle
npx bazel build :app // 10-12seconds
make change npx bazel build :app // 10-12seconds
Following https://blog.mgechev.com/2018/11/19/introduction-bazel-typescript-tutorial/ I simplified the example and made a hello-world example.
├── BUILD
├── WORKSPACE
├── package.json
├── test.ts
└── tsconfig.json
package.json
{
"name": "bazel-demo",
"license": "MIT",
"devDependencies": {
"@bazel/bazel": "^0.19.1",
"@bazel/typescript": "0.21.0",
"typescript": "^3.1.6"
}
}
WORKSPACE
workspace(name = 'lang')
http_archive(
name = "build_bazel_rules_typescript",
url = "https://github.com/bazelbuild/rules_typescript/archive/0.21.0.zip",
strip_prefix = "rules_typescript-0.21.0",
)
# Fetch our Bazel dependencies that aren't distributed on npm
load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dependencies")
rules_typescript_dependencies()
# Setup TypeScript toolchain
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
ts_setup_workspace()
# Setup the Node.js toolchain
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "yarn_install")
node_repositories()
# Setup Bazel managed npm dependencies with the `yarn_install` rule.
yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
BUILD
package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
ts_library(
name = "app",
srcs = ["test.ts"],
deps = [],
)
load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle")
rollup_bundle(
name = "bundle",
entry_point = "test.js",
deps = [":app"],
)
test.js
const hello = () => 'hello';
console.log(hello());
I would guess that npx is tainting the shell environment so that Bazel rebuilds from scratch every time. Could you try running bazel with --incompatible_strict_action_env
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.