当我从命令行运行tsc
时,我的.js
、.map
和.d.ts
文件被创建:
C:\Users\{user}\Documents\My Projects\BEPS\angular2-soap>tsc -version
Version 1.8.10
...但是当我调用以下函数时,除了文件没有创建/复制到目录Gulp
之外,一切正常:.d.ts
./app/
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;
});
package.json
我的文件中的片段:
"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"
},
我的tsconfig.json
文件:
{
"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"
]
}
我以为我需要做的就是使用dts
管道将打字文件发送到./app/
我错过了什么/做错了什么?谢谢!
尝试应用 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/'))
]);
});
访问时出错tsResults.dts
:
TypeError: Cannot read property 'pipe' of undefined
我的猜测是sourcemaps
流是正在使用的(不是typescript
流)......这有意义吗?如果是这样,我该怎么做才能解决它?
以下同时生成.js
和.d.ts
文件 - 因为它不尝试同时生成.map
文件:
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/'))
]);
});