LoginSignup
1
2

More than 5 years have passed since last update.

Typescript 環境構築メモ

Posted at

環境構築のやり方が毎回分からなくなるので、忘れても良いように記載。
おかしな所は随時訂正します。

前提条件

  1. Node.jsはインストール済み

手順

  1. gulpとgulp-typescriptのインストール
    npm install gulp gulp-typescript --save-dev

  2. TypeScript コンパイラをインストール
    npm install typescript --save-dev

  3. gulpfile.jsにtaskを定義

gulpfile.js
var gulp = require('gulp');
var typescript = require('gulp-typescript');
gulp.task('ts', () => {
    return gulp.src('./src/typescrippts/*.ts') //tsファイルを置いてるところを設定
        .pipe(typescript({
            target: 'ES5', //ECMAScript構文を指定。(デフォルトはES3)
            removeComments: true
        }))
        .js.pipe(gulp.dest('./src/js')); //jsファイルの出力先を記述
});

gulp.task('watch-ts', function() {
    gulp.watch (['./src/typescripts/*.ts'], ['ts']); //tsファイルの変更を監視し、変更された時はtsタスクが走る
});

minifyしたjsを出力するためには、別途作業が必要。

1
2
0

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
2