6

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.

2 Answers 2

10

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.
Sign up to request clarification or add additional context in comments.

Comments

-2

"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.

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.