简体   繁体   English

Typescript编译排序问题gulp-typescript,TSC 1.6

[英]Typescript compile ordering issue gulp-typescript, tsc 1.6

I am using gulp-typescript:"2.9.0" and typescript: "1.6.2" in a Visual Studio 2015 project to compile a folder of angular typescript files into a single app.js file. 我在Visual Studio 2015项目中使用gulp-typescript:“ 2.9.0”和typescript:“ 1.6.2”,将有角打字稿文件的文件夹编译为单个app.js文件。 The problem i'm having is that concatenated output order isn't correct causing angular to throw exceptions. 我遇到的问题是串联的输出顺序不正确,导致angular抛出异常。 Initially I was able to change the alphabetical order of the file names and I could get the correct order but that just stopped working. 最初,我能够更改文件名的字母顺序,并且可以获取正确的顺序,但是该命令停止了工作。 I have also tried including all of the files in the correct order in a "_references.ts" file but that doesn't seem to work. 我也尝试过将所有文件以正确的顺序包含在“ _references.ts”文件中,但这似乎不起作用。 I included the _references.ts file that i am using below. 我在下面包括了我正在使用的_references.ts文件。 The file 'app.config.ts' always appears at the top of the output and it depends on the 'app.module.ts' file. 文件“ app.config.ts”始终出现在输出的顶部,并且取决于“ app.module.ts”文件。 Does anyone have a solution for this? 有人对此有解决方案吗?

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

I managed to solve this using the gulp-angular-filesort plugin. 我设法使用gulp-angular-filesort插件解决了这个问题。 This is the typescript compilation task that made it: 这是完成它的打字稿编译任务:

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

I did not use the out option in the typescript configuration object to get a .js file for each .ts file. 我没有在打字稿配置对象中使用out选项来为每个.ts文件获取一个.js文件。 Then, after using the angular sort plugin, I concat them separately. 然后,在使用角度排序插件后,我将它们分别连接起来。

Use sortOutput parameter - set it to true like here 使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM