當我在命令行中我.js
,.map
和.d.ts
文件被創建運行tsc
:打字稿打字文件沒有被創建/複製
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/'))
]);
});
嘗試在保存'tsResults'時刪除sourcmaps.write,而是在'merge'調用'tsResults.js.pipe(sourcemaps.write())。pipe(gulp.dest())'中使用它。有很大的可能性,可能無法正常工作。我對吞嚥不太熟悉。 –
我試過幾種翻譯'sourcemaps.init()'和'sourcemaps.write()'的順序來無濟於事......但'sourcemaps'似乎是干涉... – Neoheurist