LoginSignup
1
1

More than 5 years have passed since last update.

makeでディレクトリ構成残しながらTypeScript -> JavaScript変換

Last updated at Posted at 2016-10-04

TypeScriptやろうとして、Javascriptなのでgruntやglup使うと楽ができるのかなと思って眺めてたら、眺めてるだけで疲弊したので結局make。

同じように疲弊している人がいるかもしれないので、最小限のMakefile紹介しておきます。
良かったら適当に編集して使ってください。
Windows上のMinGWで動かしていますが、大体の環境で動くのではないかと。

Makefile
help:
    #私に英語を期待しないで(´・ω・`)
    @echo make compile ... compile TypeScript
    @echo make clean ... clean output .js files

SRCDIR = ts
OUTDIR = src
SRCS = $(patsubst $(SRCDIR)/%, %, $(shell find $(SRCDIR) -name *.ts))
OUTS = $(patsubst %.ts, $(OUTDIR)/%.js, $(SRCS))
compile: $(OUTS)

$(OUTDIR)/%.js: $(SRCDIR)/%.ts
    tsc $< --outDir $(OUTDIR)

clean:
    @rm -fv $(OUTS)

SRCDIR下の階層拾ってOUTDIRに同じ構造でtscしながら格納しています。
ご自身のディレクトリ構成に合わせて書き換えてください。

ちゃんと更新チェックかけてから変換してくれるので(tsc結構遅い)、やっぱりmakeあると便利ですね。

1
1
1

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
1
1