我安装了最新的ASP.NET5 beta8并创建了新项目。在项目内部,我创建了一个新文件夹,添加了tsproject.json文件并编写了一些TypeScript文件。我想要自动编译我的TypeScript子项目。我该怎么办?我应该写些什么样的咕噜任务,在VS中启用自动的TypeScript文件编译(但它会使用tsconfig.json设置来编译文件夹中的所有文件?)还是其他?编译ASP.NET5项目中的TypeScript项目
2
A
回答
1
一个tsconfig.json文件添加到您的项目的根:
{
// TypeScript to JavaScript compilation options. Add what you want here.
"compilerOptions": {
"noImplicitAny": true, // Do not allow implicit any variables.
"noEmitOnError": true, // Stop processing on error.
"removeComments": false, // Do not remove comments.
"sourceMap": false, // Do not create source map files.
"module": "commonjs", // Use the Common JS modules or some other format.
"target": "es5" // Compile to ECMAScript 5.
},
// Exclude the bower_components, node_modules and wwwroot folders from
// being scanned for TypeScript (.ts) or TypeScript definition (.d.ts) files.
"exclude": [
"bower_components",
"node_modules",
"wwwroot"
]
}
添加gulp-typescript
编译.ts文件,gulp-concat
来连接文件和merge-stream
合并咕嘟咕嘟流至package.json
:
{
// Omitted...
"devDependencies": {
// Omitted...
"gulp-concat": "2.6.0",
"gulp-typescript": "2.9.2",
"merge-stream": "1.0.0"
}
}
在你的gulpfile.js文件中,添加一个新的构建TypeScript任务(我展示了如何进行增量构建以缩短构建时间,所以这有点高级,你可以查看文档
var gulp = require("gulp");
var concat = require("gulp-concat");
var typescript = require("gulp-typescript");
var merge = require("merge-stream");
// A TypeScript project is used to enable faster incremental compilation,
// rather than recompiling everything from scratch each time. Each
// resulting compiled file has it's own project which is stored in
// the typeScriptProjects array.
var typeScriptProjects = [];
function getTypeScriptProject(name) {
var item;
for (var i = 0; i < typeScriptProjects.length; ++i) {
if (typeScriptProjects[i].name === name) {
item = typeScriptProjects[i];
}
}
if (item === undefined) {
// Use the tsconfig.json file to specify how TypeScript (.ts)
// files should be compiled to JavaScript (.js).
var project = typescript.createProject("tsconfig.json");
item = { name: name, project: project };
typeScriptProjects.push(item);
}
return item.project;
}
var sources = {
// An array containing objects required to build a single JavaScript file.
ts: [
{
// name - The name of the final JavaScript file to build.
name: "main.js",
// paths - A single or array of paths to TypeScript files.
paths: [
"Folder1/one.ts",
"Folder1/two.ts",
"Folder2/**/*.ts"
]
}
]
};
gulp.task("build-ts", function() {
var tasks = sources.ts.map(function (source) { // For each set of source files in the sources.
return gulp // Return the stream.
.src(source.paths) // Start with the source paths.
.pipe(typescript(getTypeScriptProject(source))) // Compile TypeScript (.ts) to JavaScript (.js) using the specified options.
.pipe(concat(source.name)) // Concatenate JavaScript files into a single file with the specified name.
.pipe(gulp.dest("./wwwroot/js/")); // Saves the JavaScript file to the specified destination path.
});
return merge(tasks); // Combine multiple streams to one and return it so the task can be chained.
});
0
BTW我可以用几个tsconfig.json,并把它们里面的子文件夹:如果你想要看的东西简单)吞掉,打字稿?
TSC -p ./subfolder
相关问题
- 1. Typescript项目编译错误
- 2. 编译Android项目
- 3. 编译Android项目
- 4. 编译Izpack项目
- 5. XCode项目编译
- 6. TypeScript项目 - SystemJS
- 7. Breeze TypeScript项目中的DataType.parseDateFromServer
- 8. 编译Python项目的Windows
- 9. 设置asp.net5项目输出文件夹
- 10. MVC ASP.NET5项目模板内存泄漏
- 11. C#项目的编译器选项
- 12. 编译具有多个内部模块的TypeScript项目
- 13. ASP.net编译项目错误
- 14. 项目,wsdl2objc未编译
- 15. 编译开源项目
- 16. GWT无法编译项目
- 17. 编译器项目构想
- 18. 与Mono编译csharp项目
- 19. 用NAnt编译WebSite项目
- 20. 编译项目时出错
- 21. 编译GWT项目与Eclipse
- 22. Android项目不编译
- 23. Java项目编译错误
- 24. 编译流星项目
- 25. C++项目不编译
- 26. NetBeans不编译openGL项目
- 27. Haxe项目不编译
- 28. Msbuild不编译项目?
- 29. Silverlight项目无法编译
- 30. 帮助编译silverlight项目!
你有很多的可能性。我不亲自使用视觉工作室,但我曾与grunt合作过。在个人的基础上,我更喜欢这个。我运行一个** gulp手表**并保存它会将我的ts传输给js。我已经建立了它,所以它会保持相同的文件夹结构(而不是将所有内容编译成一个js文件)。如果你想在visual studio + typescript + angular(或不是)上提供一些建议,我强烈建议观看这个https://www.youtube.com/watch?v=Fw3ihDINdbk并检查频道。干杯。 – rottenoats
这是令人难以置信的视频!感谢您的分享! – Rem
是的,它回答了我的很多问题。这个也很好。 https://www.youtube.com/watch?v=OZxnFB0yQHs。如果你找到了你的问题的答案,请记住在这篇文章中添加答案。我相信有很多人需要澄清这个问题。 – rottenoats