gulp typescript:使用createProject时出现问题
我一直在尝试使用GulpTypeScript,并取得了一定程度的成功,但我有一个小问题。我的所有代码都存储在“src”下,我希望这些代码被编译成“.tmp”,但不包括“src” 这是我的代码,我认为问题在于不支持将值(glob)传递给tsProject.src,因此我得到了/.tmp/src/aTypescriptFile.js 这段代码是我直接从github repo获得的,我真正不明白的是为什么gulp.src会被tsProject.src取代 有什么想法吗?我确实需要合并我的tsconfig.json文件gulp typescript:使用createProject时出现问题,typescript,gulp,gulp-typescript,Typescript,Gulp,Gulp Typescript,我一直在尝试使用GulpTypeScript,并取得了一定程度的成功,但我有一个小问题。我的所有代码都存储在“src”下,我希望这些代码被编译成“.tmp”,但不包括“src” 这是我的代码,我认为问题在于不支持将值(glob)传递给tsProject.src,因此我得到了/.tmp/src/aTypescriptFile.js 这段代码是我直接从github repo获得的,我真正不明白的是为什么gulp.src会被tsProject.src取代 有什么想法吗?我确实需要合并我的tsconfi
let tsProject = plugins.typescript.createProject('./tsconfig.json');
return tsProject.src('/src/**/*.ts')
.pipe(plugins.typescript(tsProject))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest('.tmp'));
**编辑**
更多信息,我已经设法用一个glob来限制它,通过替换
return tsProject.src('/src/**/*.ts')
与
现在的问题是,我得到了一个关于丢失打字的错误
src/testme.ts(4,10): error TS2304: Cannot find name 'require'.
我的TSCONFIG.JSON文件在这里,里面有打字
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"files": [
"typings/main.d.ts",
"src/testme.ts"
]
}
所有路径都应传递到gulp.src——源和类型 让我们有一些途径:
var paths = {
lib: "./wwwroot/",
ts: ["./sources/**/*.ts"],
styles: ["./sources/**/*.scss"],
templates: ["./sources/**/*.html"],
typings: "./typings/**/*.d.ts",
//svg: "./sources/**/*.svg",
};
我们可以将一组源路径传递给gulp typescript:
gulp.task("?typescript:demo:debug", function () {
var tsResult = gulp.src([
paths.typings,
// <...some other paths...>
].concat(paths.ts))
.pipe(sourcemaps.init())
.pipe(ts({
target: "ES5",
experimentalDecorators: true,
noImplicitAny: false
}));
return tsResult.js
.pipe(concat(package.name + ".js"))
.pipe(sourcemaps.write({ sourceRoot: "" }))
.pipe(gulp.dest(paths.lib));
})
谢谢,我将接受这一点,因为它对我帮助很大,但最终我通过保留原始代码并在tsconfig.json中添加“rootDir”:“src”解决了这个问题。因此,如果有人发现了这一点,有两种解决方案。
gulp.task("?typescript:demo:debug", function () {
var tsResult = gulp.src([
paths.typings,
// <...some other paths...>
].concat(paths.ts))
.pipe(sourcemaps.init())
.pipe(ts({
target: "ES5",
experimentalDecorators: true,
noImplicitAny: false
}));
return tsResult.js
.pipe(concat(package.name + ".js"))
.pipe(sourcemaps.write({ sourceRoot: "" }))
.pipe(gulp.dest(paths.lib));
})
gulp.src([paths.typings, <...some other paths...>].concat(paths.ts))
gulp.src([paths.typings, paths.ts])