【发布时间】:2017-01-28 23:17:34
【问题描述】:
不太确定以下配置有什么问题,但由于某种原因,它不想转译我项目的 ts 文件。如下所示,它在运行 gulp 任务时甚至不会抛出任何错误。它就像一切正常一样运行,并且不生成任何 .js 文件,也不创建构建目录。
(也在管理员模式下测试过,但没有运气)
当我手动运行 tsc -p config/tsconfig.json 时一切正常
版本:
λ gulp -v
[00:13:03] CLI version 1.2.2
[00:13:03] Local version 3.9.1
+-- typescript@2.1.5
λ node -v
v6.9.4
项目目录结构:
-
src/
- app/(包含所有app ts文件)
-
配置/
- tsconfig.json
gulpfile.js
- package.json
gulpfile.js:
const gulp = require('gulp');
const del = require('del');
const tsc = require("gulp-typescript");
const sourcemaps = require('gulp-sourcemaps');
var config = {
jit: {
root: './build/jit',
index: 'index-jit.html'
},
aot: {
root:'./build/aot/dist',
index: 'index-aot.html'
}
};
gulp.task("compile:jit", () => {
let tsProject = tsc.createProject("config/tsconfig.json");
log("[JIT] Compiling all .ts files")
let tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject());
return tsResult.js
.pipe(sourcemaps.write(".", {sourceRoot: '/src'}))
.pipe(gulp.dest(tsProject.options.outDir));
});
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"lib": [ "es2015", "dom" ],
"outDir": "../build/jit/app",
"suppressImplicitAnyIndexErrors": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"sourceMap": true,
"typeRoots": [
"../node_modules/@types/"
]
},
"include": [
"../src/**/*.ts"
],
"exclude": [
"../node_modules",
"../src/**/*-aot.ts"
]
}
运行gulp -LLLL compile:jit时得到的唯一输出
[23:49:34] Using gulpfile [project_dir]/gulpfile.js
[23:49:34] Starting 'compile:jit'...
[23:49:34] [JIT] Compiling all .ts files
[23:49:34] Finished 'compile:jit' after 75 ms
【问题讨论】:
-
您使用的是什么版本的 typescript/tsc gulp-typescript?有没有我们可以自己签出和编译/试用的 git 项目?因为我确实没有看到直接的问题:/ - 参考github.com/aredfox/electron-starter - 我似乎有一个类似的设置,我可以毫无问题地运行。附言;并不是说它会影响结果,使用“npm i @types/
--save(--dev)”时不再需要字节“typeRoots” - 因为它现在会自动查找它。跨度> -
ps;我看到您正在使用 tsConfig 中的“outDit”。您是否尝试定义 gulp.dest('./some/path/') 以查看发生了什么?另一方面,为什么我要求我们可以克隆的 git repo 是因为我发现 tsc 和 gulp-typescript 有时确实会静默失败 - 并且在没有输出时很难调试。
-
我已经用 Typescript 版本更新了帖子。我将尝试整理一个示例供您查看整个项目。问题是,我在其他计算机上使用相同的配置与 win7 并且一切工作正常。现在当我复制它然后在我的另一台计算机(win 10)上使用相同的配置构建项目时它似乎不起作用。我还会仔细检查 tsc、node gulp 的版本是否相同.. 但我仍然看不出它不应该工作的任何原因。
-
也没有看到特定的原因。你是否也全局安装了 gulp 和 typescript ?一个例子会很有用——也许也可以尝试在 typescript 问题页面的 GitHub 页面上发布它,他们也可以参考或帮助你。我会等你的榜样!
-
我目前正在使用 typescript 2.5 - 也许尝试更新(它是新的和稳定的),您是否特别需要 2.1?也许试试my git repo - 你可以克隆 / 和 npm install / 然后编辑 node_modules/@types/dot-object/index.d.ts - as there's an error waiting to be solved - 只需将pick的返回值从void修复为any。如果my repo 也没有在那里运行,那么:( :/.. 这里是 win7/10 macOS 和 linux mint - 所以试试看?
标签: node.js typescript gulp