We recently encountered an issue on our build server where the generated javascript was not working sporadically. After investigation, we found that the order of the code in the generated file was arbitrary, leading to the malfunction.
After reading through https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html, it seems like using outFile may not be the best practice and it might be time to switch to a proper module system. It's puzzling why this problem suddenly appeared out of nowhere.
If switching to a module system is the solution, which one would be recommended?
The snippet from gulpfile.js looks as follows:
var gulp = require("gulp");
var sourcemaps = require('gulp-sourcemaps');
var ts = require('gulp-typescript');
var tsLint = require('gulp-tslint');
var tsProject = ts.createProject('tsconfig.json', {}, ts.reporter.longReporter());
var config = {
maps: './maps',
scripts: './content/scripts'
};
gulp.task('tslint', function() {
return tsProject.src()
.pipe(tsLint({
configuration: {
rules: { "semicolon": true }
}
}))
.pipe(tsLint.report('verbose'));
});
gulp.task('typescript',['tslint'], function() {
var tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(ts(tsProject))
.pipe(sourcemaps.write(config.maps))
.pipe(gulp.dest(config.scripts));
return tsResult;
});
And here is the content of tsconfig.json:
{
"compilerOptions": {
"declaration": false,
"noEmitOnError": false,
"noImplicitAny": false,
"removeComments": false,
"target": "es5",
"outFile": "application.js"
},
"files": [
"list of all the files"
]
}