2016-09-21 40 views

回答

9

目前v1.0.0您只能選擇您要通過以下命令來構建應用程序:

ng build -a appName

ng build --app appName

,你還需要name屬性添加到每個元素在apps陣列,所以你會有這樣的事情:

"apps": [ { "name": "app1", "root": "src/app1root", ... }, { "name": "app2", "root": "src/app2root", ... }, ... ]

,你也可以在你不需要指定應用程序的名稱這種情況下使用應用程序的索引像ng build -a 0ng build -a 1

從角CLI sorces你可以看到,有沒有可能在運行一個命令所有的應用程序,您應該指定指數無論是應用程序的名稱,否則apps[0]將被使用,所以你不能在同一構建所有的應用程序時間使用一個ng build電話。

5

我搜索了angular-cli源代碼,但找不到任何代碼的引用,這些代碼將迭代或以其他方式檢查apps的內容作爲數組。

截至目前(angular-cli版本1.0.0-beta.15),處理apps的每個代碼實例都使用硬編碼數組的第一個元素(apps[0])。似乎沒有辦法選擇應用程序來構建或更改使用數組第一個元素的默認行爲。

的JSON模式爲apps元這樣描述:在這個項目中的不同應用的

屬性。

/** 
* Properties of the different applications in this project. 
*/ 
apps?: { 
    root?: string; 
    outDir?: string; 
    assets?: string; 
    index?: string; 
    main?: string; 
    test?: string; 
    tsconfig?: string; 
    prefix?: string; 
    mobile?: boolean; 
    /** 
    * Global styles to be included in the build. 
    */ 
    styles?: string[]; 
    /** 
    * Global scripts to be included in the build. 
    */ 
    scripts?: string[]; 
    /** 
    * Name and corresponding file for environment config. 
    */ 
    environments?: { 
     [name: string]: any; 
    }; 
}[]; 

這似乎是該項目支持建立多個應用了相同的代碼庫的未來意圖,但它並不像它是正確的事情,現在是可行的(1.0.0版本beta.15 )。

+0

好的,我將離開這個問題,希望angular-cli開發人員在不久的將來實現它。 – Readren

+1

我覺得有棱角的cli缺乏文檔干擾 – Kamaruni

+0

@Kamaruni我也這麼認爲。我的希望是,他們會隨着時間的推移變得更好,特別是現在角2決賽已經結束。至少有Github頁面:https://github.com/angular/angular-cli不要忘記Wiki:https://github.com/angular/angular-cli/wiki –

2

仍有不ng build --app建立所有應用程序使用一個命令,來解決這個問題是創建的Makefile文件在項目的根所以最好的方式任何標誌:

my-app 
    --dist/ 
    --e2e/ 
    --src/ 
    .angular-cli.json 
    package.json 
    Makefile 

Makefile文件允許組織根據您提供的說明進行代碼編譯。 因此,我們需要提供指令,將所有應用程序的前端構建到輸出目錄中。 現在的Makefile文件是這樣的:上面

help: 
    @echo "_______BUILD ANGULAR FRONTEND______\n" 
    @echo "To build all apps run make make build-frontend" 

build-frontend: 
    ng build -a=0 &&\ 
    ng build -a=1 

您但是經過複製粘貼代碼,改變空間的設置選項卡。否則,你會得到無效的Makefile *** missing separator error

導航到根項目,只是爲了測試,在終端中輸入make,你應該得到幫助信息打印。此類型之後:

make build-frontend 

現在,您只有一個命令即可構建多個應用程序。

相關問題