问题描述
我一直在尝试使用gulp-typescript取得一定程度的成功,但我有一个小问题。我所有的代码都存储在'src'下,我希望这些代码被编译为'.tmp',但不包含'src'。
这里是我的代码,我认为问题在于传递值(glob)到tsProject.src不支持,所以我得到/.tmp/src/aTypescriptFile.js例如这个代码我直接从github回购,我真的不明白为什么gulp.src被tsProject.src替换
任何想法?我确实需要合并我的tsconfig.json文件。
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'));
**编辑**
更多info,我已经设法限制它使用glob通过替换
return tsProject.src('/ src / ** / * .ts')
with
return gulp.src('/ src / ** / *。ts')
问题现在我得到一个关于缺少类型的错误。
src / testme.ts(4,10 ):错误TS2304:找不到名字'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],
样式:[./sources/**/*.scss],
模板:[./sources/**/*.html],
类型:。 /typings/**/*.d.ts,
// svg:./sources/**/*.svg,
};
我们可以将一组源文件路径传递给gulp-typescript:
gulp.task(?typescript:demo:debug,function(){
var tsResult = gulp.src([
paths .typings,
//< ...其他路径...>
] .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])
I have been trying to use gulp-typescript with some degree of success but I have a small issue. All my code is stored under 'src' and I want these to be compiled to '.tmp' but without the 'src' being included.
here is my code, I think the issue is that passing a value (glob) to tsProject.src isn't supported so I get /.tmp/src/aTypescriptFile.js for example
This code I got directly from the github repo, what I really didn't understand is why gulp.src is replaced with tsProject.src
Any ideas ? I do really need to incorporate my tsconfig.json file.
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'));
** EDIT **
More info, I have managed to confine it using a glob by replacing the
return tsProject.src('/src/**/*.ts')
with
return gulp.src('/src/**/*.ts')
problem is now that I get an error about missing typings.
src/testme.ts(4,10): error TS2304: Cannot find name 'require'.
my TSCONFIG.JSON file is here, which has the typings in there.
{
"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"
]
}
All paths should be passed to gulp.src -- sources and typings.
Let us have some paths:
var paths = {
lib: "./wwwroot/",
ts: ["./sources/**/*.ts"],
styles: ["./sources/**/*.scss"],
templates: ["./sources/**/*.html"],
typings: "./typings/**/*.d.ts",
//svg: "./sources/**/*.svg",
};
We can pass an array of source paths to 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));
})
I'm passing
gulp.src([paths.typings, <...some other paths...>].concat(paths.ts))
but of course, it can also be done in a simpler way:
gulp.src([paths.typings, paths.ts])
这篇关于gulp-typescript:使用createProject的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!