Skip to content

pubref/rules_typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rules_typescript Build Status

Bazel Typescript rules_closure

Strongly typed typescript goes in, optimized & minified javascript comes out 🉐.

Rules

Name Description
typescript_repositories Load dependencies for this repository.
ts_library Invoke the typescript compiler on a set of *.ts files to generate a set of *.js files.
ts_binary Optimize and minify a set of *.js files with closure compiler via rules_closure.

Status: PROOF OF CONCEPT. It probably only works under very narrow conditions at the moment.

Usage

Prerequisite: java8 and bazel should installed on your system.

WORKSPACE Configuration

1. Add rules_closure to your WORKSPACE

git_repository(
  name = "io_bazel_rules_closure",
  remote = "https://github.com/bazelbuild/rules_closure",
  tag = "0.4.0",
)

This brings in rules_closure, which is actually a different front-end to the closure compiler with additional type checking and goodies.

2. Add rules_node to your WORKSPACE

git_repository(
  name = "org_pubref_rules_node",
  remote = "https://github.com/pubref/rules_node",
  commit = HEAD, # replace with latest version
)

This brings in an independent copy of node, typescript (2.1.4), and tsickle (0.21.0, experimental).

3. Add rules_typescript to your WORKSPACE

git_repository(
  name = "org_pubref_rules_typescript",
  remote = "https://github.com/pubref/rules_typescript",
  commit = HEAD, # replace with latest version
)

load("@org_pubref_rules_typescript//ts:rules.bzl", "ts_repositories")
ts_repositories()

BUILD Configuration

ls_library

Compile typescript files with tsc, the typescript compiler.

load("@org_pubref_rules_typescript//ts:rules.bzl", "ts_library")

ts_library(
  name = "lib",
  srcs = [
    "a.ts",
    "b.ts",
    "c.ts",
  ],
  # Optional tsconfig file.  If provided, you don't need to specify 'files'.
  ts_config = "tsconfig.json",
)

ls_binary

Compile generated javascript from ts_library dependencies into single minified output via the closure_js_binary rule.

load("@org_pubref_rules_typescript//ts:rules.bzl", "ts_binary")

ts_binary(
  name = "app",
  deps = [
    ":lib",
  ],
)

The generated file will take the form:

var {TS_BINARY_RULE_NAME} = function(){%output%};

Therefore, you can invoke the entry point for the minified bundle:

<html>
 <head>
  <script src="{TS_BINARY_RULE_NAME}.js"></script>

 </head>
 ...
 <script>{TS_BINARY_RULE_NAME}();</script>
</html>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages