如何使用angular-cli构建多个应用程序?

Rea*_*ren 19 angular-cli

属性appsangular-cli.json的文件是阵列类型.如果我在这个数组中添加第二个元素,我该如何指示ng build构建这两个元素?

Leo*_*Leo 10

目前,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 0或者ng build -a 1在这种情况下您不需要指定应用程序名称.

从angular-cli sorces中你可以看到没有可能在一个命令中运行所有应用程序,你应该指定索引,否则apps[0]将使用app name ,因此你不能使用一个ng build调用同时构建所有应用程序.


Cul*_*tes 8

用你的package.json

"scripts": {
   "build-projects": "ng build project1 && ng build project2",
}
Run Code Online (Sandbox Code Playgroud)

然后运行:npm run build projects.


Dav*_* M. 5

我搜索了angular-cli源代码,但找不到任何对迭代或以其他方式检查apps数组内容的代码的引用.

截至目前(angular-cli版本1.0.0-beta.15),处理的每个代码实例都apps使用数组的第一个元素hardcoded(apps[0]).似乎没有办法选择应用程序来构建或更改使用数组的第一个元素的默认行为.

apps元素的JSON模式以这种方式描述它:

此项目中不同应用程序的属性.

/**
 * 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;
    };
}[];
Run Code Online (Sandbox Code Playgroud)

该项目的未来意图似乎是支持使用相同的代码库构建多个应用程序,但它看起来不像现在可行(1.0.0-beta.15版本).