GithubHelp home page GithubHelp logo

rules_typescript-1's Introduction

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>

rules_typescript-1's People

Contributors

pcj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.