用bazel编译打字稿很慢?

时间:2019-03-10 15:22:08

标签: javascript typescript bazel

问题:在bazel中发布初始构建时间超过10秒,这正常吗?下面的示例如何减少Bazel的构建时间?

命令:

yarn
npx bazel build :bundle 
npx bazel build :app // 10-12seconds

进行更改     npx bazel build:app // 10-12秒

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

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());

1 个答案:

答案 0 :(得分:0)

我想npx会污染外壳环境,因此Bazel每次都会从头开始重建。 您可以尝试使用--incompatible_strict_action_env

运行bazel吗?