Last active
April 14, 2017 09:08
-
-
Save kkeeth/1057040de554df03077e to your computer and use it in GitHub Desktop.
テスト用gulpfile.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* やるタスクは | |
* riot.jsで書かれたtagファイルのコンパイル | |
* typescriptで書かれたjsファイルのコンパイル | |
* コンパイルされたjsファイルのminify | |
* minifyされたjsファイルの*.min.jsにリネーム | |
*/ | |
const gulp = require('gulp'), | |
riot = require('gulp-riot'), | |
tsc = require('gulp-typescript'), | |
uglify = require('gulp-uglify'), | |
rename = require('gulp-rename'), | |
plumber = require('gulp-plumber'), | |
eslint = require('gulp-eslint') | |
// パスの一覧 | |
const paths = { | |
ts_dir : 'path_to_tscdir/*.ts', | |
js_dir : 'path_to_jsdir/*.js', | |
tag_dir : ';path_to_tagdir/*.tag' | |
build_dir: 'path_to_build/' | |
} | |
// ESLintチェック | |
gulp.task('eslint', () => { | |
gulp.src(paths.js_dir) | |
.pipe(plumber({ | |
errorHandler: (error) => { | |
let taskName = 'eslint'; | |
let title = '[task]' + taskName + ' ' + error.plugin; | |
let errorMsg = 'error: ' + error.message; | |
// ターミナルにエラーを出力 | |
console.error(title + '\n' + errorMsg); | |
} | |
})) | |
.pipe(eslint.format()) | |
.pipe(eslint.failOnError()) | |
.pipe(buble()) | |
.pipe(uglify()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest(paths.js_dir)) | |
.pipe(plumber.stop()) | |
}) | |
// typescriptコンパイル | |
// minify | |
// min.jsにリネーム | |
gulp.task('typescript', () => { | |
gulp.src(paths.ts_dir) | |
.pipe(tsc()) | |
.pipe(uglify()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest('js')) | |
}); | |
// riotコンパイル | |
// minify | |
// min.jsにリネーム | |
gulp.task('riot', () => { | |
gulp.src(paths.tag_dir) | |
.pipe(riot({ | |
compact: true, | |
type: 'typescript', | |
})) | |
.pipe(uglify()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest('js')); | |
}); | |
// 指定のディレクトリに変更したtsファイルがあれば自動でタスク実行 | |
gulp.task('watch', () => { | |
gulp.watch(paths.ts_dir, ['typescript']); | |
}); | |
// 全タスクを実行 | |
gulp.task('default', ['typescript', 'riot']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment