LoginSignup
4
3

More than 5 years have passed since last update.

【改訂】TypeScriptのtsc -wでコンパイルされない件。

Last updated at Posted at 2013-01-10

2019/02/01 改訂: コンパイルされるようになっていました

tscのVersion 3.3.1で、ファイルの変更を検知して自動的にコンパイルされるようになっていました :tada:

↓以下の内容は古いままです。

問題

TypeScriptのtscコマンドにおける-w(--watch:ソースファイルの変更を検知して自動的にコンパイルしてくれるオプション)が、どうも効いていない。

変更を検知するが、jsファイルを出力してくれない。

環境

OS:Ubuntu 12.10 64bit
npm:1.1.69
TypeScript:0.8.1?

実行すると

$ tsc form.ts -w

Recompiling(Thu Jan 10 2013 00:46:49 GMT+0900 (JST)): /usr/lib/node_modules/typescript/bin/lib.d.ts,/path/form.ts

のような表示はされるが、form.jsファイルが出力されず。

ソースを変更すると上記の"Recompiling xxx"というのは表示されるものの、やっぱりjsファイルは出力されず。

回避方法

どうもバグのようですが、2013/1現在、修正されていない模様。

てことで

Typescript watch compiler

を使います。

これは、tscコマンドのwatchを常に行うようにしたものです。

インストールは以下の通り。

sudo npm install -g tscw

実行すると

$ tscw form.ts

TSCW is watching for changes, initializing first recompile.

  -> recompiling... done.

となり、ディレクトリを確認すると無事form.jsファイルが作成されていました。

※tscw -w form.ts ではない点に注意。

また、ソースを修正すると

$ tscw form.ts

TSCW is watching for changes, initializing first recompile.

  -> recompiling... done.

[1:10:11]: change detected in file form.ts

  -> recompiling... done.

となり、変更を検知してコンパイルされていました。

tscwコマンドは、tscコマンドのオプションすべてが使えるようです。

4
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3