Within my tasks.json file, I have two tasks - a build-task and a gulp task that utilizes gulp-typescript. Unfortunately, the latter is not functioning as expected, and the reason behind this issue eludes me. Both tasks are configured to use the same tsconfig.json configuration file.
The gulp-task ("tsc") runs without any errors but fails to generate the src/test.js file specified in the tsconfig.json (outFile). After thorough investigation, I am unable to locate the generated file anywhere within the folder structure. On the contrary, the build task successfully generates the file.
I suspect there might be a version inconsistency between typescript and gulp-typescript causing this problem. With the frequent updates and changes, finding the accurate solution through online search results has proven to be quite challenging.
Initially, I assumed that gulp-typescript functions as a seamless wrapper around typescript. However, this assumption appears to be incorrect as it seems to possess its own method of generating sourcemaps and disregards certain settings from tsconfig.json.
tasks.json:
{
// Refer to https://go.microsoft.com/fwlink/?LinkId=733558
// for detailed documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"taskName": "tsc",
"command": "gulp.cmd",
"args": ["tsc"]
}
]
}
gulpfile.js:
var gulp = require('gulp'),
less = require('gulp-less'),
plumber = require('gulp-plumber'),
uglify = require('gulp-uglify'),
notify = require('gulp-notify'),
concat = require('gulp-concat'),
template = require('gulp-angular-templatecache'),
htmlminifier = require('gulp-html-minify'),
chmod = require('gulp-chmod'),
cachebust = require('gulp-cache-bust'),
runSequence = require('run-sequence'),
tsc = require("gulp-typescript"),
webserver = require('gulp-webserver'),
flatten = require('gulp-flatten'),
gutil = require('gulp-util'),
gulpif = require('gulp-if'),
debug = require('gulp-debug'),
rename = require('gulp-rename'),
sourcemaps = require('gulp-sourcemaps'),
argv = require("yargs").argv;
...
let compileTypescript = function() {
var tsProject = tsc.createProject("tsconfig.json");
var tsResult =
tsProject
.src()
.pipe(sourcemaps.init())
.pipe(tsProject());
return
tsResult.js
.pipe(sourcemaps.write())
.pipe(gulp.dest('src'));
};
gulp.task('tsc', compileTypescript);
tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"target": "es5",
"allowJs": false,
"noImplicitUseStrict": true,
"rootDir": "./src",
"noEmitOnError": true,
"module": "none",
"moduleResolution": "node",
"noImplicitReturns": true,
"outFile": "src/test.js",
"removeComments": true,
"skipLibCheck": true,
"allowUnreachableCode": false,
"allowSyntheticDefaultImports": false,
"allowUnusedLabels": false,
"sourceMap": true,
"declaration": false
},
"exclude": [
"node_modules",
"dist",
"src/scripts/typings/node",
"src/scripts/typings/jasmine",
"src/**/*.js",
"src/**/__*.*"
]
}
package.json:
{
"name": "Test",
"author": {
"name": "Test Company",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="691d0c1a1d291d0c1a1d470a0604">[email protected]</a>",
"url": "http://test.com/"
},
"version": "1.0.0",
"devDependencies": {
"gulp": "3.9.1",
"gulp-connect":"5.0.0",
"gulp-angular-templatecache": "2.0.0",
"gulp-chmod": "2.0.0",
"gulp-concat": "2.6.1",
"gulp-flatten": "0.3.1",
"gulp-html-minify": "^0.0.14",
"gulp-debug":"3.1.0",
"gulp-inject": "4.2.0",
"gulp-less": "3.3.2",
"gulp-rename":"1.2.2",
"gulp-notify": "3.0.0",
"gulp-plumber": "1.1.0",
"gulp-rimraf": "0.2.1",
"gulp-sourcemaps": "2.6.0",
"gulp-tslint": "8.1.1",
"gulp-typescript": "^3.2.1",
"gulp-uglify": "3.0.0",
"gulp-using": "0.1.1",
"gulp-util": "3.0.8",
"webpack-stream":"3.2.0",
"gulp-if":"2.0.2",
"gulp-watch": "4.3.11",
"gulp-cache-bust": "1.1.0",
"gulp-webserver": "0.9.1",
"run-sequence":"2.1.0",
"yargs": "8.0.2",
"stream-combiner2": "1.1.1",
"typescript": "2.4.2",
"tslint":"5.5.0"
}
}