[英]Typescript compile ordering issue gulp-typescript, tsc 1.6
我在Visual Studio 2015項目中使用gulp-typescript:“ 2.9.0”和typescript:“ 1.6.2”,將有角打字稿文件的文件夾編譯為單個app.js文件。 我遇到的問題是串聯的輸出順序不正確,導致angular拋出異常。 最初,我能夠更改文件名的字母順序,並且可以獲取正確的順序,但是該命令停止了工作。 我也嘗試過將所有文件以正確的順序包含在“ _references.ts”文件中,但這似乎不起作用。 我在下面包括了我正在使用的_references.ts文件。 文件“ app.config.ts”始終出現在輸出的頂部,並且取決於“ app.module.ts”文件。 有人對此有解決方案嗎?
/// <reference path="../typings/angularjs/angular.d.ts" />
/// <reference path="../typings/jquery/jquery.d.ts" />
/// <reference path="../typings/angularjs/angular-route.d.ts" />
/// <reference path="app.module.ts" />
/// <reference path="app.zconfig.ts" />
/// <reference path="app/framework/framework.module.ts" />
/// <reference path="app/framework/psframework.directive.ts" />
/// <reference path="app/framework/menu/menu.module.ts" />
/// <reference path="app/framework/menu/menu.directive.ts" />
/// <reference path="app/framework/menu/menu-item.directive.ts" />
/// <reference path="app/framework/dashboard/dashboard.module.ts" />
我設法使用gulp-angular-filesort插件解決了這個問題。 這是完成它的打字稿編譯任務:
gulp.task('compile', function () {
var pathsArray = paths.js.typescriptDefinitionFile.concat(paths.js.src);
gulp.src(pathsArray)
.pipe(typescript({
target: 'es5',
noImplicitAny: true,
preserveConstEnums: true
}))
.pipe(angularFilesort())
.pipe(concat(paths.js.srcOutputFile))
.pipe(gulp.dest(paths.js.outputFolder));
});
我沒有在打字稿配置對象中使用out選項來為每個.ts文件獲取一個.js文件。 然后,在使用角度排序插件后,我將它們分別連接起來。
使用sortOutput參數-像這里將其設置為true
var tscResult = srcResult
.pipe(gulpTypeScript({
typescript: require('typescript'),
sortOutput: true,
target: "ES5",
declarationFiles: true,
noEmitOnError: dontEmitTSbuildErrors,
out: "./obj/" + outFileName + ".js"
}, undefined, gulpTypeScript.reporter.longReporter()));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.