2015-10-11 28 views
0

我想有以下目錄結構多吞掉的來源和目的地

-- src |__ app |__ x.ts |__ test |__ y.ts -- build |__ app |__ js |__ test |__ js

我想,關於「一飲而盡編譯」,我有我的生成js文件編譯/內部應用程序和構建/測試。即我有多個來源和多個目的地。 我不想爲測試創建一個新的gulp目標。以下是其中兩個我試圖完成的任務

gulp.task('compile', function() { 
    //path to src/app typescript files 
    var app_js = gulp.src('./src/app/**/*.ts') 
     .pipe(tsc(tsProject)) 
    //path to src/test typescript files 
    var test_js = gulp.src('./src/test/**/*.ts') 
     .pipe(tsc(tsProject)); 
    return merge([ 
     app_js.js.pipe(gulp.dest('./build/src/app/')), 
     test_js.js.pipe(gulp.dest('./build/src/test/')) 
    ]); 
}); 

gulp.task('bundle', function() { 
    var paths = [ 
     { src: './src/app/**/*.ts', dest: './build/src/app/' }, 
     { src: './src/test/**/*.ts', dest: './build/src/test/' } 
    ]; 
    var tasks = paths.map(function (path) { 
     return gulp.src(path.src).pipe(tsc(tsProject)).pipe(gulp.dest(path.dest)); 
    }) 
    return merge(tasks); 
}); 

然而,每一次,我跑「一飲而盡編譯」或「大口捆綁」的各種方法,我打了下列問題

events.js:141 throw er; // Unhandled 'error' event ^Error: stream.push() after EOF at readableAddChunk (_stream_readable.js:132:15)

有人能告訴我,我在這裏做錯了什麼? 注意:我嘗試使用merge-stream和merge2包。

回答

0

我在我的項目之一,在同一個項目的結構和我使用的構建任務如下:

var tsProject = tsc.createProject({ 
    removeComments : false, 
    noImplicitAny : false, 
    target : "ES5", 
    module : "commonjs", 
    declarationFiles : false 
}); 

gulp.task("build-source", function() { 
    return gulp.src(__dirname + "/source/**/**.ts") 
      .pipe(tsc(tsProject)) 
      .js.pipe(gulp.dest(__dirname + "/build/source/")); 
}); 

var tsTestProject = tsc.createProject({ 
    removeComments : false, 
    noImplicitAny : false, 
    target : "ES5", 
    module : "commonjs", 
    declarationFiles : false 
}); 

gulp.task("build-test", function() { 
    return gulp.src(__dirname + "/test/*.test.ts") 
      .pipe(tsc(tsTestProject)) 
      .js.pipe(gulp.dest(__dirname + "/build/test/")); 
}); 

gulp.task("build", function(cb) { 
    runSequence("lint", "build-source", "build-test", cb); 
}); 

我使用兩個獨立的任務,因爲使用一個tsProject對象與多個源和多個目的地會導致意想不到的行爲。

You must create the project outside of the task. You can't use the same project in multiple tasks. Instead, create multiple projects or use a single task to compile your sources. - Source

我還使用了捆綁任務如下:

gulp.task("bundle-source", function() { 
    var b = browserify({ 
    standalone : 'inversify', 
    entries: __dirname + "/build/source/inversify.js", 
    debug: true 
    }); 

    return b.bundle() 
    .pipe(source("inversify.js")) 
    .pipe(buffer()) 
    .pipe(gulp.dest(__dirname + "/bundled/source/")); 
}); 

gulp.task("bundle-test", function() { 
    var b = browserify({ 
    entries: __dirname + "/build/test/inversify.test.js", 
    debug: true 
    }); 

    return b.bundle() 
    .pipe(source("inversify.test.js")) 
    .pipe(buffer()) 
    .pipe(gulp.dest(__dirname + "/bundled/test/")); 
}); 

gulp.task("bundle", function(cb) { 
    runSequence("build", "bundle-source", "bundle-test", "document", cb); 
}); 

我的整個構建腳本可用here。希望能幫助到你!

0

Ower!感謝您的及時迴應。

我結束了以下解決方案

gulp.task('compile', function() { 
    return gulp.src(['src/**/*.ts']) 
     .pipe(sourcemaps.init()) 
     .pipe(tsc(tsProject)) 
     .pipe(sourcemaps.write('.')) 
     .pipe(gulp.dest('build')); 
});"