打字稿输出顺序 - gulp 等同于 tsc with tsconfig.json
typescript output order - gulp equivalent to tsc with tsconfig.json
给定一个 tsconfig 文件并使用命令行 tsc,一切正常。但是,将 gulp-typescript
与指定的 tsconfig.json
和 outFile
一起使用会创建不同的输出顺序 - 我的问题是我找不到 gulp 生成相同 [=53] 的方法=] 和 tsc 一样。
我们的构建工作流程基于gulp;但是 tsc
是黄金标准,具有良好的监视功能,并且具有广泛的工具支持(例如 http://dev.ivogabe.com/using-vscode-with-gulp-typescript/)。如果我能让我们基于 gulp 的构建工作与 tsc 相同,那就太好了。
示例tsconfig.json
:
{
"compilerOptions": {
"declaration": false,
"preserveConstEnums": true,
"outFile": "out/out.js",
"sourceMap": true,
"target": "es5",
"noEmitOnError": true
},
"exclude": [
"node_modules",
"out"
]
}
示例gulpfile.js
:
"use strict";
var gulp = require('gulp');
var typescript = require('gulp-typescript');
var tsProject = typescript.createProject('tsconfig.json');
gulp.task('typescript:compile', function () {
var tsResult = tsProject.src()
.pipe(typescript(tsProject));
return tsResult.js.pipe(gulp.dest('out'));
});
gulp.task('default', ['typescript:compile']);
同样,我的问题是tsc
与上面的tsconfig.json
;和 gulp
以及上面的 gulpfile.js
和 tsconfig.json
(使用 gulp-typescript
)为打字稿文件的重要目录产生不同的输出顺序。开发人员应该能够在两个构建过程之间任意切换,并确信他们没有错过输出排序错误。
我不明白用于 tsc
和 gulp-typescript
的输出排序规则之间的区别,所以我无法为这个问题创建一个简单的重现案例。但理想情况下 gulp-typescript
在使用 tsconfig 项目时会使用与 tsc
.
相同的顺序
我可以通过使用 "child-process".exec 调用 tsc 来解决这个问题,但是 gulp-typescript
有更好的 gulp 集成;我也愿意使用任何其他 gulp 直接调用打字稿编译器的插件(并使用 tsconfig.json 项目文件),但我一直没能找到。
my problem is that I can't find a gulp way to generate the same javascript as tsc does
TypeScript 有一个内部排序实现:
- 命令行中传递的文件顺序。如果您是 tsconfig,则不相关。
- 检测文件的顺序。由于您使用的是 tsconfig,它将从第一个文件开始,然后按
references
和 import
指令对其他文件进行排序。
注意:不适用于 API 消费者(例如gulp)。这也可能导致问题,即使只有 tsc
:https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md
所以使用外部模块:https://basarat.gitbooks.io/typescript/content/docs/project/modules.html
这是一个快速入门:https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html
给定一个 tsconfig 文件并使用命令行 tsc,一切正常。但是,将 gulp-typescript
与指定的 tsconfig.json
和 outFile
一起使用会创建不同的输出顺序 - 我的问题是我找不到 gulp 生成相同 [=53] 的方法=] 和 tsc 一样。
我们的构建工作流程基于gulp;但是 tsc
是黄金标准,具有良好的监视功能,并且具有广泛的工具支持(例如 http://dev.ivogabe.com/using-vscode-with-gulp-typescript/)。如果我能让我们基于 gulp 的构建工作与 tsc 相同,那就太好了。
示例tsconfig.json
:
{
"compilerOptions": {
"declaration": false,
"preserveConstEnums": true,
"outFile": "out/out.js",
"sourceMap": true,
"target": "es5",
"noEmitOnError": true
},
"exclude": [
"node_modules",
"out"
]
}
示例gulpfile.js
:
"use strict";
var gulp = require('gulp');
var typescript = require('gulp-typescript');
var tsProject = typescript.createProject('tsconfig.json');
gulp.task('typescript:compile', function () {
var tsResult = tsProject.src()
.pipe(typescript(tsProject));
return tsResult.js.pipe(gulp.dest('out'));
});
gulp.task('default', ['typescript:compile']);
同样,我的问题是tsc
与上面的tsconfig.json
;和 gulp
以及上面的 gulpfile.js
和 tsconfig.json
(使用 gulp-typescript
)为打字稿文件的重要目录产生不同的输出顺序。开发人员应该能够在两个构建过程之间任意切换,并确信他们没有错过输出排序错误。
我不明白用于 tsc
和 gulp-typescript
的输出排序规则之间的区别,所以我无法为这个问题创建一个简单的重现案例。但理想情况下 gulp-typescript
在使用 tsconfig 项目时会使用与 tsc
.
我可以通过使用 "child-process".exec 调用 tsc 来解决这个问题,但是 gulp-typescript
有更好的 gulp 集成;我也愿意使用任何其他 gulp 直接调用打字稿编译器的插件(并使用 tsconfig.json 项目文件),但我一直没能找到。
my problem is that I can't find a gulp way to generate the same javascript as tsc does
TypeScript 有一个内部排序实现:
- 命令行中传递的文件顺序。如果您是 tsconfig,则不相关。
- 检测文件的顺序。由于您使用的是 tsconfig,它将从第一个文件开始,然后按
references
和import
指令对其他文件进行排序。
注意:不适用于 API 消费者(例如gulp)。这也可能导致问题,即使只有 tsc
:https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md
所以使用外部模块:https://basarat.gitbooks.io/typescript/content/docs/project/modules.html
这是一个快速入门:https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html