angular default project (angular.json的解读)

时间:2022-05-29 19:51:13

Change the default Angular project

Understanding it's purpose and limits

angular default project (angular.json的解读)
Nov 6, 2018

Angular's default project is nothing more than a string, set in angular.json, to say which project should run with ng commands without a defined project.

Note: The defaultProject key was set to be deprecated in 7.0.0 , but it was blocked because there should be a large discussion about project layout for 8.x.x.

Let's create a new project called my-app:

$ ng new my-app

It will create an angular.json with the following structure:

{
...,
"projects": {
"my-app": { ... },
"my-app-e2e": { ... },
},
"defaultProject": "my-app",
}

So, when you run ng serve , it would serve my-app. It would be the same as running ng serve my-app.

Setting a new default project

To understand what values are valid, let's create a library and an application.

$ ng create application my-application
$ ng create library my-library

Now, we have the following structure:

{
...,
"projects": {
"my-app": { ... },
"my-app-e2e": { ... },
"my-application": { ... },
"my-application-e2e": { ... },
"my-library": { ... }
},
"defaultProject": "my-app",
}

The highlighted values ( my-appmy-application and my-library) are the valid ones to use as the defaultProject. E2E projects are not valid ones, even if they are listed as projects, because they are used on ng e2e.

If you created a blank workspace or just deleted the default project string, the first project you create (in this case my-application) will automatically be set as the default project.

Commands

Each project type has their own commands to use, for example:
Applications: servebuildteste2e and xi18n.
Libraries: build and test.