2013-01-24 55 views
2

我已經下載了一個使用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.

這是我的文件結構是怎樣的樣子:

Solution

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 ->'&quot;%(fullpath)&quot;', ' ')" /> 
    <Exec Command="tsc $(TypeScriptSourceMap) --out all.js @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" /> 
</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(); 
}); 
+0

當您使用'--out'標誌時,不需要將所有文件傳遞給編譯器。將它傳遞給頂層文件,它將遍歷依賴關係並發現所有其他文件。這與AMD不兼容 - 捆綁是一種不同的技術,因爲所有的腳本都在一個文件中,因此所有腳本都將被加載。 – Fenton

+0

相關:[TypeScript問題:將JavaScript輸出結合到文件中並不顯示工作](https://typescript.codeplex.com/discussions/545710) – xmojmr

回答

4

按照定義,AMD腳本是由AMD加載程序異步加載的。爲了將它們全部放在一個文件中,您需要對每個文件的依賴性進行一些分析,以便它們按正確的順序插入。這不是--out所做的。您需要調查RequireJS optimizer之類的內容。

+0

根據文章,我安裝了'Node.Js'並試圖像'node r.js -o app/AppConfig.js'一樣設置'後期構建事件命令行'。我得到一個錯誤立即'命令「節點r.js -o app/AppConfig.js」用代碼9009退出。「(不管我如何改變'r.js'和'AppConfig.js'我在主帖中粘貼了AppConfig.js的內容)。 – Nickon

+1

我建議在將它集成到VS構建步驟之前,讓您的構建從命令行腳本運行。但是,請參閱[在此構建過程中「代碼9009退出的含義」是什麼意思?](http://stackoverflow.com/questions/1351830/what-does-exited-with-code-9009-mean-during-this-build )可能的解決方案 – ryan

+0

這有所幫助。從命令行一切工作正常。我在一個批處理文件中執行它,它正在作爲'後期構建事件...'運行。感謝幫助!祝你有美好的一天! – Nickon