admin管理员组

文章数量:1294383

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

Is it possible to configure such that the cli will instead generate new ponent folders in app/ponents/{ponentName}/ folder?

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

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

Is it possible to configure such that the cli will instead generate new ponent folders in app/ponents/{ponentName}/ folder?

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

Share asked Jul 6, 2016 at 13:59 CarvenCarven 15.7k30 gold badges124 silver badges184 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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. ponents, services) in a grouped directory.

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

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

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

I disagree here, though the remendation 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 e 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, ponents, pages, etc. grouped together, then well organized within that folder structure. Components shared across pages would go into a "ponents/mon" folder, for example, while ponents belonging to a specific page may be found under "ponents/" with each page having a "root" ponent.

But then, my apps tend to be pretty beastly.

本文标签: javascriptChanging default folder for components in angularcliStack Overflow