Carven
Carven

Reputation: 15648

Changing default folder for components in angular-cli

Currently, the Angular CLI creates a new component by default in the app/{componentName}/ folder.

Is it possible to configure such that the cli will instead generate new component folders in app/components/{componentName}/ folder?

I tried messing around with some variables in the angular-cli.json but with no luck.

Upvotes: 6

Views: 6131

Answers (2)

Javin007
Javin007

Reputation: 9

"The reason for this is that the style guide suggests not placing all like entities (i.e. components, services) in a grouped directory."

I disagree here, though the recommendation may have changed on the style guide you posted over the past 7 years. Now the style guide states:

"Do make locating code intuitive and fast."

"To work efficiently you must be able to find files quickly, especially when you do not know (or do not remember) the file names. Keeping related files near each other in an intuitive location saves time. A descriptive folder structure makes a world of difference to you and the people who come after you."

"Do keep a flat folder structure as long as possible."

"Consider creating sub-folders when a folder reaches seven or more files."

I prefer to keep my pipes, services, components, pages, etc. grouped together, then well organized within that folder structure. Components shared across pages would go into a "components/common" folder, for example, while components belonging to a specific page may be found under "components/" with each page having a "root" component.

But then, my apps tend to be pretty beastly.

Upvotes: -1

Brocco
Brocco

Reputation: 64853

There is nothing like that in place in the CLI for a persistent value. The reason for this is that the style guide suggests not placing all like entities (i.e. components, services) in a grouped directory.

With that being said to achieve this you have two options...

  1. Change the directory of your command line/terminal to app/components/ and generate from there. The CLI will know your current directory and create relative to that directory
  2. When you generate each component from the root of your project (or src dir) you can specify ng generate component components/foo which will include "components" in the path of where the component is generated.

Upvotes: 10

Related Questions