使用gulp-watch观看多个文件夹

时间:2015-10-08 14:48:39

标签: typescript gulp gulp-watch

我的项目中有这样的文件夹结构:

  • 通用
  • 游戏
    • 的Game1
    • GAME2
    • ...

每个文件夹都包含一个Typescript文件列表,所有游戏都与Common文件夹有依赖关系。

使用Typescript编译所有内容大约需要10秒钟。是否可以创建一个分别观看每个游戏的gulp-watch?

这就是我现在所做的工作:

// Compile
gulp.task('compile-games', ['clean-games'], function () {
var folders = getFolders(inputPaths.games);

var gameTasks = folders.map(function (folder) {
    return gulp.src([
            path.join(inputPaths.common, '/**/*.ts'),
            path.join(inputPaths.games, folder, '/**/*.ts')], { base: inputPaths.scripts })
        .pipe(sourcemaps.init({ loadMaps: true }))
        .pipe(typescript({
            target: "ES5",
            noImplicitAny: false,
            sortOutput: true
        }))
        .pipe(concat('Game.js'))
        .pipe(sourcemaps.write('./', { includeContent: true, debug: true }))
        .pipe(gulp.dest(path.join(outputPaths.games, folder)));
});

// Watches
gulp.task('watch', function () {
    gulp.watch(path.join(inputPaths.games, "**/*.ts"), ["compile-games"]);
    gulp.watch(path.join(inputPaths.common, "**/*.ts"), ["compile-games"]);
});

1 个答案:

答案 0 :(得分:1)

这不是您正在寻找的解决方案,但它应该可以解决您的构建时间问题:

gulp.watch([path.join(inputPaths.games, "**/*.ts"), path.join(inputPaths.common, "**/*.ts")], ['compile-games']);

...然后安装gulp-newer:

npm install --save-dev gulp-newer

...然后在你的'编译游戏'任务中,在gulp.src之后直接将流传输到gulp-newer插件中。结果:只重建了新更改的文件,并且只对这些文件进行了Typescript编译。