我安裝了最新的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. 的MSBuild不編譯項目
- 10. 編譯Xcode項目的編譯錯誤
- 11. 如何在.Net Core項目中禁用TypeScript編譯?
- 12. MVC ASP.NET5項目模板內存泄漏
- 13. 設置asp.net5項目輸出文件夾
- 14. C#項目的編譯器選項
- 15. 在項目中不使用Kotlin編譯的項目
- 16. Visual Studio 2012未採用ASP.NET MVC4項目的最新編譯TypeScript
- 17. 編譯具有多個內部模塊的TypeScript項目
- 18. VSO ASP.NET5 CI編譯期間出錯 - 「您的項目使用不同版本的TypeScript編譯器」但我沒有使用TypeScript
- 19. TeamCity編譯項目編譯錯誤
- 20. 用NAnt編譯WebSite項目
- 21. 幫助編譯silverlight項目!
- 22. 編譯Xcode項目下載
- 23. 無法編譯grails項目
- 24. 項目不會編譯
- 25. Java項目編譯錯誤
- 26. 從SVN Gradle編譯項目
- 27. NetBeans不編譯openGL項目
- 28. 與Mono編譯csharp項目
- 29. 編譯流星項目
- 30. apportable項目編譯錯誤
你有很多的可能性。我不親自使用視覺工作室,但我曾與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