Skip to content

instantdelay/sbt-typescript

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#sbt-typescript Build Status This sbt plugin compiles the Typescript code in your Play application to javascript fit for consumption by your average browser and device.

###introduction The aim of this plugin is to make it easy to write Angular2 applications using the Play framework.
As such it

  • allows transpiling to a single output file. This is important for large applications. At least for as long as http2 isn't prevalent.
  • uses the standard tsconfig.json file for configuration.
  • Most editors and IDEs use this file to resolve types in the typescript code you're writing.
  • Also it allows setting of all tsc options. Even the undocumented ones.
  • And it allows you to switch between sbt-typescript and tsc.
  • allows resolution of module imports against webjars. Since every Angular2 application uses ES6 module imports this is obviously an important requirement.
  • allows for including typings files in the build. This is essential for compilation to ES5 because the standard ES5 lib doesn't have some types that f.i. Angular2 needs. These types are offered for ES5 by ao ES6-shims.
  • allows for suppression of compilation errors. This may seem strange to people coming from conventional statically typed languages. But the tsc lives in an untyped world. So it will emit perfectly functional code even if some types can't be checked. Suppression of a specific error is particularly useful if one's using a library for which type information is not available.
  • supports writing unittests in typescript
  • uses Typescript 1.8.10
  • JS parts are written in Typescript.

###getting started with Typescript and Angular2 I've made an activator tutorial template to get you started. If you have activator installed you can run activator new play-angular2-typescript. Or you can just clone the repo.

###configuring Create a tsconfig.json file in the root of your project with the required compiler options.
Add the following line to your project\plugins.sbt:

addSbtPlugin("name.de-vries" % "sbt-typescript" % "0.2.7")

If your project is not a Play application it will have to enable sbt-web in build.sbt:

lazy val root = (project in file(".")).enablePlugins(SbtWeb)

####configuring an IDE If you want to use an IDE like IntelliJ you can use the task sbt setupTscCompilation. At this point that copies the npm webjars to <base-dir>/node_modules. Then you can point the IDE to your tsconfig.json.

####compiling to a single js file You can develop using individual javascript files when running sbt ~run in Play and have your whole typescript application concatenated into a single javascript output file for your stage environment without changes to your sources. To do that you have to add a -DtsCompileMode=stage parameter to the sbt task in your CI that creates the stage app. So for Play that will often be sbt stage -DtsCompileMode=stage.

####typings If you have a typings file you can add it like this:

typingsFile := Some(baseDirectory.value / "typings" / "browser.d.ts")

See src/sbt-test/sbt-typescript/es6-es5 for an example.

####resolve against webjar npms If you want to resolve modules against webjar npms:

resolveFromWebjarsNodeModulesDir := true

This will use the npm webjar directory to resolve types of modules. See src/sbt-test/sbt-typescript/angular2 for an example. Make sure to use npm webjars as your dependencies.

####import modules without type information If you are importing modules for which you don't have the typings you can ignore the TS2307 can not find module error:

tsCodesToIgnore := List(canNotFindModule)

####ignored compiler options The following tsc compiler options are managed by sbt-typescript so setting them in tsconfig.json has no effect:

  • outDir and
  • rootDir.
    If you use the stage compile mode the outFile option is also managed by sbt-typescript.

##release notes

v0.3.0SNAPSHOT

  • uses standard typescript functionality to resolve against webjars. Instead of the previous custom rolled module resolution extension.
  • uses a snapshot of the upcoming typescript 2.0

v0.2.7

  • adds convenience task for setting up tsc compilation

v0.2.6

  • fixes jstaskfailure error

v0.2.5

  • allows for developing using individual javascript files and using a single javascript file in production

v0.2.4

  • upgrades to typescript 1.8.10

v0.2.3

  • upgrades to typescript 1.8.7
  • adds support for tests in typescript

v0.2.2

  • upgrades to typescript 1.8.2
  • improves output of single outfile
  • fixes a nasty bug in module resolution. This is essential for angular2 applications.
  • gives feedback on faulty compiler options.

##status The plugin is young. Currently it is mostly tested against EngineType.Node and Angular2 applications with npm style dependencies.
There are some other features I'm planning to implement.

##history I started this plugin because the features I mentioned above were missing in the existing plugins.
And since I'd like Play and sbt(-web) to be kickass build tools for Typescript and Angular2 applications, and I wanted to give back to the open source community, I thought I'd implement it myself.. But not by writing javascript if I could just as well write Typescript...
Kudos to Brendan Arp for his javascript tsc driver to get me started. And also to all of the other plugins mentioned here. Open source is an amazing tool for collective learning. Just imagine those poor programmers in the 1970s with only IBM manuals to provide them with information.

About

An sbt plugin for compiling typescript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 40.6%
  • TypeScript 35.6%
  • JavaScript 19.0%
  • HTML 4.8%