简体   繁体   中英

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. The problem i'm having is that concatenated output order isn't correct causing angular to throw exceptions. 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. I included the _references.ts file that i am using below. The file 'app.config.ts' always appears at the top of the output and it depends on the 'app.module.ts' file. 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. 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. Then, after using the angular sort plugin, I concat them separately.

Use sortOutput parameter - set it to true like here

var tscResult = srcResult
        .pipe(gulpTypeScript({
            typescript: require('typescript'),
            sortOutput: true,
            target: "ES5",
            declarationFiles: true,
            noEmitOnError: dontEmitTSbuildErrors,
            out: "./obj/" + outFileName + ".js"
        }, undefined, gulpTypeScript.reporter.longReporter()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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