gulp-typescript:使用 createProject 时出现问题

gulp-typescript: Problems using createProject

我一直在尝试使用 gulp-typescript 并取得了一定程度的成功,但我遇到了一个小问题。我所有的代码都存储在 'src' 下,我希望将它们编译为“.tmp”但不包含 'src'。

这是我的代码,我认为问题是不支持将值(glob)传递给 tsProject.src 所以我得到 /.tmp/src/aTypescriptFile.js 例如

这段代码我直接从github repo 得到的,我真正不明白的是为什么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'));

** 编辑 **

更多信息,我已经设法通过替换

使用 glob 来限制它
             return tsProject.src('/src/**/*.ts')

             return gulp.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));
})

我路过

gulp.src([paths.typings, <...some other paths...>].concat(paths.ts))

当然,也可以用更简单的方式来实现:

gulp.src([paths.typings, paths.ts])