When I run tsc
from the command line my .js
, .map
, and .d.ts
files are created:
C:\Users\{user}\Documents\My Projects\BEPS\angular2-soap>tsc -version
Version 1.8.10
...but when I invoke the following Gulp
function everything works except that the .d.ts
files are not created/copied to the ./app/
directory:
gulp.task('compile-typescript', function () {
var sourcemaps = require('gulp-sourcemaps');
var typescript = require('gulp-typescript');
var typescriptCompiler = typescript({typescript: require('typescript')});
var typescriptProject = typescript(typescript.createProject('tsconfig.json'));
var tsResults = gulp.src(['!./src/**/spec*.ts', './src/**/*.ts'])
.pipe(typescriptProject)
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('../map/'))
.pipe(gulp.dest('./app/'))
.pipe(typescriptCompiler).dts.pipe(gulp.dest('./app/'));
return tsResults;
});
snippet from my package.json
file:
"devDependencies": {
"autoprefixer": "6.3.6",
"concurrently": "2.0.0",
"cssnano": "3.5.2",
"del": "2.2.0",
"gulp": "3.9.1",
"gulp-ext-replace": "0.3.0",
"gulp-imagemin": "2.4.0",
"gulp-postcss": "6.1.0",
"gulp-sourcemaps": "1.6.0",
"gulp-typescript": "2.13.0",
"http-server": "0.9.0",
"jasmine-core": "2.4.1",
"karma": "0.13.22",
"karma-chrome-launcher": "0.2.3",
"karma-jasmine": "0.3.8",
"karma-spec-reporter": "0.0.26",
"lite-server": "2.2.0",
"postcss": "5.0.19",
"postcss-scss": "0.1.7",
"precss": "^1.3.0",
"run-sequence": "1.1.5",
"systemjs": "0.19.26",
"typescript": "latest",
"typings": "0.8.1"
},
my tsconfig.json
file:
{
"compileOnSave": true,
"compilerOptions": {
"target": "ES5",
"module": "System",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"noImplicitAny": true,
"declaration": true,
"sourceMap": true,
"mapRoot": "map/",
"diagnostics": true
},
"exclude": [
"node_modules",
"typings"
]
}
I thought that all I needed to do was to use the dts
pipe to send the typing files to ./app/
What am I missing/doing incorrectly? Thanks!
Attempting to apply the suggestion from t34t5:
gulp.task('compile-typescript', function () {
var sourcemaps = require('gulp-sourcemaps');
var typescript = require('gulp-typescript');
var project = typescript.createProject('tsconfig.json', {declaration: true});
var merge = require('merge2');
var tsResults = gulp.src(['!./src/**/spec*.ts', './src/**/*.ts'])
.pipe(sourcemaps.init())
.pipe(typescript(project))
.pipe(sourcemaps.write('../map/'));
return merge([
tsResults.dts.pipe(gulp.dest('./app/')),
tsResults.js.pipe(gulp.dest('./app/'))
]);
});
I get an error accessing tsResults.dts
:
TypeError: Cannot read property 'pipe' of undefined
My guess is that the sourcemaps
stream is what is being used (not the typescript
stream)... does this make sense? if so, what can I do to fix it?
The following generates both the .js
and .d.ts
files - because it's not trying to also generate .map
files:
gulp.task('compile-typescript', function () {
var typescript = require('gulp-typescript');
var project = typescript.createProject('tsconfig.json', {declaration: true});
var merge = require('merge2');
var tsResults = gulp.src(['!./src/**/spec*.ts', './src/**/*.ts'])
.pipe(typescript(project));
return merge([
tsResults.dts.pipe(gulp.dest('./app/')),
tsResults.js.pipe(gulp.dest('./app/'))
]);
});