我已經下載了一個使用AMD
的項目。一切工作正常,但我想測試如何連接所有編譯的文件到一個輸出all.js
文件。我發現一些有關--out
參數,並遵循從這裏步驟:https://stackoverflow.com/a/14302902/1252575TypeScript + AMD + out參數不起作用
它沒有爲我工作,我得到了一個錯誤:
The command "tsc --module AMD --out all.js "C:\TypeScriptWithRequireAMD_0.8.1\app\classes\Test.ts" "C:\TypeScriptWithRequireAMD_0.8.1\modules\require.d.ts" "C:\TypeScriptWithRequireAMD_0.8.1\app\classes\Greeter.ts" "C:\TypeScriptWithRequireAMD_0.8.1\app\AppConfig.ts" "C:\TypeScriptWithRequireAMD_0.8.1\app\AppMain.ts"" exited with code 1.
這是我的文件結構是怎樣的樣子:
Btw。我有第二個問題。目錄中是否有--out
參數複製內容lib
?如果不是,如何包括它們呢?
[編輯1]
哦,我忘了......這是我.csproj
文件的一部分:
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<TypeScriptSourceMap>--module AMD</TypeScriptSourceMap>
</PropertyGroup>
<Target Name="BeforeBuild">
<Message Text="Compiling TypeScript files" />
<Message Text="Executing tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
<Exec Command="tsc $(TypeScriptSourceMap) --out all.js @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
</Target>
[編輯2]
這裏是我的AppConfig.js
:
require.config({
baseUrl: '../',
paths: {
'jquery': 'lib/jquery-1.7.2',
'underscore': 'lib/underscore',
'backbone': 'lib/backbone',
'console': 'lib/console',
'greeter': 'app/classes/Greeter',
'test': 'app/classes/Test'
},
shim: {
jquery: {
exports: '$'
},
underscore: {
exports: '_'
},
backbone: {
deps: [
"underscore",
"jquery"
],
exports: "Backbone"
},
console: {
exports: "console"
},
greeter: {
deps: [
"test"
]
},
test: {
deps: [
"greeter"
]
}
}
});
require([
'jquery',
'underscore',
'backbone',
'console',
'app/AppMain',
'app/classes/Greeter',
'app/classes/Test'
], function ($, _, Backbone, console, main, greeter, test) {
var appMain = new main.AppMain();
appMain.run();
});
當您使用'--out'標誌時,不需要將所有文件傳遞給編譯器。將它傳遞給頂層文件,它將遍歷依賴關係並發現所有其他文件。這與AMD不兼容 - 捆綁是一種不同的技術,因爲所有的腳本都在一個文件中,因此所有腳本都將被加載。 – Fenton
相關:[TypeScript問題:將JavaScript輸出結合到文件中並不顯示工作](https://typescript.codeplex.com/discussions/545710) – xmojmr