JsFan
JsFan

Reputation: 443

Use Angular cli with existing project

I have an existing project and I want to use the angular cli generator, so After install and create the following .angular-cli file:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "app"
  },
  "apps": [
    {
      "root": "src/mc2/components",
      "prefix": "app"
    }
  ],
  "defaults": {
    "styleExt": "css",
    "component": { }
  }
}

The problem is when I generate a new component it created inside:

/src/mc2/components/app/todos/...

How can I remove the app folder, what I really need is:

/src/mc2/components/todos/...

Upvotes: 0

Views: 1573

Answers (2)

angularconsulting.au
angularconsulting.au

Reputation: 28319

Fist of all you have to follow the CLI project structure, so just run ng new my-app and make sure that you have a matching structure in your project, once it is done change your "root": "src/mc2/components" to "root": "src" in .angular-cli.json

If you are in the root of your project folder the rule is

  • ng g c something - create something component in src/app/something
  • ng g c /components/something - create something component in src/app/components/something

Also you can use --flat flag to create a component without a dedicated folder
You can add --dry-run just to see what the command is gonna do

Upvotes: 1

Krister Torsvik
Krister Torsvik

Reputation: 82

Sorry, seems that i mislead you. Because of the angular-cli style guide the ng g component something always places your generated component inside an app folder. Didn't find a way to change this except manually doing so. But when you generate a new file it just generates a new app folder. So for now i dont think they have made a way to do this yet.

Upvotes: 0

Related Questions