2015-09-19 74 views
0

我使用一饮而尽,打字稿:“2.9.0”和打字稿:“1.6.2”在一个Visual Studio 2015年项目的角度打字稿文件的文件夹编译成一个单一的app.js文件。我遇到的问题是连接的输出顺序不正确,导致角度抛出异常。最初,我能够改变文件名的字母顺序,我可以得到正确的顺序,但只是停止工作。我也尝试在“_references.ts”文件中以正确的顺序包含所有文件,但似乎并不奏效。我在下面使用了_references.ts文件。文件'app.config.ts'总是出现在输出的顶部,它取决于'app.module.ts'文件。有没有人有这个解决方案?打字稿编译订货问题一饮而尽,打字稿,TSC 1.6

/// <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" /> 

回答

0

使用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())); 
+0

排序输出不适合我。它仍然会将这些文件串联在_references文件中指定的顺序之外。我最终不得不在tsconfig.json文件的文件集合中按顺序列出每个文件。问题是一个角度模块被声明在一个文件中,然后在另一个文件中使用。 Typescript不理解这个顺序,所以我需要定义它。我已经将所有外部模块一起移动。 – Brandt

1

我管理这个使用一饮而尽,角文件排序插件来解决。这是打字稿编译任务,使得它:

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)); 
}); 

我没有用了打字稿配置对象的出选项以获得每个.TS文件.js文件。然后,在使用角度排序插件后,我分别连接它们。