[英]Using bazel to compile typescript is very slow?
問題:在bazel中發布初始構建時間超過10秒,這正常嗎? 下面的示例如何減少Bazel的構建時間?
命令:
yarn
npx bazel build :bundle
npx bazel build :app // 10-12seconds
更改npx bazel build:app // 10-12seconds
在https://blog.mgechev.com/2018/11/19/introduction-bazel-typescript-tutorial/之后,我簡化了示例並制作了hello-world示例。
├── 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(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",
)
建立
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());
我想npx會污染外殼環境,因此Bazel每次都會從頭開始重建。 您可以嘗試使用--incompatible_strict_action_env運行bazel嗎
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.