Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@daikiojm

angular-cliでappフォルダ直下にコンポーネントを作成したい

More than 3 years have passed since last update.

angular-cliのng generate componentappフォルダ直下にコンポーネントを作成したい場合は、--flatオプションを付けるか、.angular-cli.jsonで設定を変更します。

環境

確認を行った環境

@angular/cli: 1.3.0
node: 8.1.3
os: darwin x64

設定前

ng generate componentでコンポーネントを作成

ng g component test

/src/app以下は次のようなディレクトリ構成になる

src
├── src/app
│   ├── src/app/app.component.css
│   ├── src/app/app.component.html
│   ├── src/app/app.component.spec.ts
│   ├── src/app/app.component.ts
│   ├── src/app/app.module.ts
│   └── src/app/test
│       ├── src/app/test/test.component.css
│       ├── src/app/test/test.component.html
│       ├── src/app/test/test.component.spec.ts
│       └── src/app/test/test.component.ts
...略...

設定する

設定ファイルを変更して常にflatオプションを有効にする場合

defaults->component->flatをtrueに設定します。

.angular-cli.json
{
// ...略...
  "defaults": {
    "styleExt": "css",
    "component": {
      "flat": true
    }
  }
}

確認する

ng generate componentでコンポーネントを作成

オプションを使用

ng g component --flat test

設定ファイルを変更済みの場合

ng g component test

app以下には他のファイルと同列にコンポーネントが配置されている

src
├── src/app
│   ├── src/app/app.component.css
│   ├── src/app/app.component.html
│   ├── src/app/app.component.spec.ts
│   ├── src/app/app.component.ts
│   ├── src/app/app.module.ts
│   ├── src/app/test.component.css
│   ├── src/app/test.component.html
│   ├── src/app/test.component.spec.ts
│   └── src/app/test.component.ts
...略...

参考

angular-cli -wiki
https://github.com/angular/angular-cli/wiki/generate-component

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
daikiojm
https://daikiojm.me/

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?