0

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

I don't understand, the prefix as a meaning in the structure?

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.