简体   繁体   English

Ng 构建到多个项目 angular

[英]Ng build to multiple projects angular

Hello I have a workspace in angular with two applications app1 and app2.您好,我在 angular 中有一个工作区,其中包含两个应用程序 app1 和 app2。

My question is, how do you upload to the server?我的问题是,你如何上传到服务器? The two applications and workspace with the package.json configuration of workspace obviously.这两个应用程序和工作空间同package.json配置工作空间明显。

When I have a single application, I upload the contents of the dist folder.当我有一个应用程序时,我会上传 dist 文件夹的内容。

But now I don't know但现在我不知道

If you are using Angular CLI Workspace.如果您使用的是 Angular CLI 工作区。 then it's actually easy.那么这实际上很容易。 If you have two or more projects.如果您有两个或更多项目。 Example app1 , app2 .示例app1app2

To build app1构建 app1

ng build --project app1  --prod  

Your build will be stored in dist/app1 .您的构建将存储在dist/app1中。 you can copy that to your server您可以将其复制到您的服务器

To build app2构建 app2

ng build --project app2  --prod  

Your build will be stored in dist/app2 .您的构建将存储在dist/app2中。 you can copy that to your server您可以将其复制到您的服务器

Bonus Add those lines to your package.json inside the scripts property奖金将这些行添加到脚本属性内的package.json

 {
  "name": "testapp",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build:app1": "ng build --project app1  --prod",
    "build:app2": "ng build --project app2  --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

Then you can run if you are using npm然后如果你使用的是npm就可以运行

npm run build:app1

or if you are using yarn或者如果你使用纱线

yarn build:app1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM