系统配置
第一次使用angular2时 我的文件夹示例/服务器结构位于
之下|-- server.js
|-- server.ts
|-- tsconfig.json
|-- typings
| |-- browser
| | `-- ambient
| | |-- express
| | | `-- express.d.ts
| | |-- mime
| | | `-- mime.d.ts
| | |-- node
| | | `-- node.d.ts
| | `-- serve-static
| | `-- serve-static.d.ts
| |-- browser.d.ts
| |-- main
| | `-- ambient
| | |-- express
| | | `-- express.d.ts
| | |-- mime
| | | `-- mime.d.ts
| | |-- node
| | | `-- node.d.ts
| | `-- serve-static
| | `-- serve-static.d.ts
| `-- main.d.ts
`-- typings.json
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"files": [
"./server/typings/main.d.ts",
"./server/server.ts"
],
"exclude": [
"node_modules",
// even used ../node_modules as the folder is located above this folder
"typings/browser.d.ts",
"typings/browser"
]
}
{
"ambientDependencies": {
"express": "github:DefinitelyTyped/DefinitelyTyped/express/express.d.ts#d1f6bde13f2209be42e86c3686761e8bfcbb50a5",
"mime": "github:DefinitelyTyped/DefinitelyTyped/mime/mime.d.ts#d1f6bde13f2209be42e86c3686761e8bfcbb50a5",
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#aee0039a2d6686ec78352125010ebb38a7a7d743",
"serve-static": "github:DefinitelyTyped/DefinitelyTyped/serve-static/serve-static.d.ts#0fa4e9e61385646ea6a4cba2aef357353d2ce77f"
}
}
var path = require('path');
var gulp = require('gulp');
var gutil = require('gulp-util');
var ts = require('gulp-typescript');
gulp.task('log', function() {
gutil.log('== My Log Task ==')
});
gulp.task('buildServer', function () {
var tsProject = ts.createProject('./server/tsconfig.json');
return gulp.src('./server/**/*.ts')
.pipe(ts(tsProject))
.js
.pipe(gulp.dest('./server'))
});
/// <reference path="main/ambient/express/express.d.ts" />
/// <reference path="main/ambient/mime/mime.d.ts" />
/// <reference path="main/ambient/node/node.d.ts" />
/// <reference path="main/ambient/serve-static/serve-static.d.ts" />
运行时
usernam@hostname:~/sample$ gulp buildServer
它给出了类似于下面的655个错误,引用了node.d.ts的每一行
server / typings / browser / ambient / node / node.d.ts(754,9):错误TS2300:重复的标识符&#39;内部&#39;
...
....
server / typings / main / ambient / node / node.d.ts(1943,18):错误TS2300: 重复的标识符&#39;域&#39;
...
.....
服务器/分型/主/环境/服务静电/服务-static.d.ts(85,5): 错误TS2300:重复的标识符&#39; export =&#39;。
最后它会停止
[22:38:56] TypeScript: 655 semantic errors
[22:38:56] TypeScript: emit succeeded (with errors)
我注意到它首先为 main / 文件夹提供了错误,而不是 browser / 文件夹
我的猜测是问题与 gulpfile.js ; 在gulpfile.js中进行以下更改
return gulp.src('./server/**/*.ts')
返回gulp.src('./server/main/*.ts')
然后 gulp buildServer 运行但立即完成。
.js
做了什么? 请建议解决这个问题的工作是什么。我已经在网上看过,但现在找不到任何工作。
答案 0 :(得分:2)
除了包含定义文件的所有*.ts
文件外,请尝试仅包括除*.ts
以外的所有 *.d.ts
文件的所有main.d.ts
个文件。
gulp.src(['server/**/*.ts', '!server/**/*.d.ts', 'server/typings/main.d.ts'])
或(不是100%关于如何按照我的头脑中的排序工作)
gulp.src(['server/**/*.ts', 'server/typings/main.d.ts', '!server/**/*.d.ts'])
更新:我最终使用merge2
合并了两个gulp.src
个流。
var gulp = require('gulp');
var merge = require('merge2');
var typescript = require('gulp-typescript');
gulp.task('build', function() {
var tsFiles = gulp.src('server/**/*.ts', '!server/typings/**');
return merge(tsFiles, gulp.src('server/typings/main.d.ts'))
.pipe(typescript(...));
});