我目前有打字稿问题。我正在尝试使用有关使用 express 构建服务器的简单教程( http://blog.edenmsg.com/angular2-typescript-gulp-and-expressjs/ )。所以我按照说明使用tsd安装express。然后我尝试按照此文件中的说明启动 gulp 构建:
gulpfile.js
/**
* Created by alicia on 10/03/2016.
*/
var gulp = require('gulp');
var path = require('path');
var sourcemaps = require('gulp-sourcemaps');
var ts = require('gulp-typescript');
var del = require('del');
var concat = require('gulp-concat')
var runSequence = require('run-sequence');
// SERVER
gulp.task('clean', function(){
return del('dist')
});
gulp.task('build:server', function () {
var tsProject = ts.createProject('server/tsconfig.json');
var tsResult = gulp.src('server/**/*.ts')
.pipe(sourcemaps.init())
.pipe(ts(tsProject))
return tsResult.js
.pipe(concat('server.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist'))
});
// CLIENT
/*
jsNPMDependencies
*/
var jsNPMDependencies = [
'angular2/bundles/angular2-polyfills.js',
'systemjs/dist/system.src.js',
'rxjs/bundles/Rx.js',
'angular2/bundles/angular2.dev.js',
'angular2/bundles/router.dev.js'
]
gulp.task('build:index', function(){
var mappedPaths = jsNPMDependencies.map(file => {return path.resolve('node_modules', file)})
//Let's copy our head dependencies into a dist/libs
var copyJsNPMDependencies = gulp.src(mappedPaths, {base:'node_modules'})
.pipe(gulp.dest('dist/libs'));
var copyCss = gulp.src('client/css/**/*.css')
.pipe(gulp.dest('dist/css'));
//Let's copy our index into dist
var copyIndex = gulp.src('client/index.html')
.pipe(gulp.dest('dist'));
return [copyJsNPMDependencies, copyCss, copyIndex];
});
gulp.task('build:app', function(){
var tsProject = ts.createProject('client/tsconfig.json');
var tsResult = gulp.src('client/**/*.ts')
.pipe(sourcemaps.init())
.pipe(ts(tsProject))
return tsResult.js
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist/app'))
});
var typescript = require('gulp-tsc');
gulp.task('compile', function(){
gulp.src(['client/**/*.ts'])
.pipe(typescript())
.pipe(gulp.dest('dist/'))
});
gulp.task('build', function(callback){
runSequence('clean', 'build:server',
'build:index',
'build:app',
callback);
});
gulp.task('default', ['build'])
除了 build:server 之外,每个任务都会编译(clean、build:index...)。这是我得到的错误:
[12:07:43] Starting 'build:server'...
server/typings/node/node.d.ts(1759,52): error TS1005: '=' expected.
server/typings/node/node.d.ts(1760,76): error TS1005: '=' expected.
server/typings/node/node.d.ts(1761,52): error TS1005: '=' expected.
server/typings/node/node.d.ts(1761,96): error TS1005: '=' expected.
server/typings/node/node.d.ts(1771,54): error TS1005: '=' expected.
server/typings/node/node.d.ts(1772,74): error TS1005: '=' expected.
server/typings/node/node.d.ts(1773,54): error TS1005: '=' expected.
server/typings/node/node.d.ts(1773,94): error TS1005: '=' expected.
显然问题来自node.d.ts。我真的不知道为什么它不工作,即使它是在绝对类型上找到的版本。您对如何提供帮助有任何想法吗?
编辑:我还包括我的 tscongig.json
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"module": "commonjs",
"target": "es6",
"sourceMap": true,
"outDir": "dist",
"declaration": false,
"jsx": "react",
"noImplicitAny": false,
"removeComments": false
},
"exclude": [
"node_modules",
"typings/browser.d.ts",
"typings/browser"
]
}