LoginSignup
5
2

More than 3 years have passed since last update.

Angularでコンポーネント名を変更するにはWebStormが便利だという話

Last updated at Posted at 2019-11-02

コンポーネントのrename辛い

Angularでアプリケーション開発中にコンポーネント名を変更したくなるタイミングが多々あると思います。
Angularでコンポーネント名を変更するとなると、

  • *.component.ts で定義しているcomponentのclass名
  • *.component.html, *.component.scss, *.component.spec.ts, *.component.tsの各ファイル名
  • *.component.ts@componentデコレーターで指定しているslecector, templateUrl, styleUrls
  • 上記のファイル群を包括しているディレクトリ名
  • 変更したコンポーネントをimportしているファイル(*.module.tsとか)

を変更するという流れになると思います。
普段私が使っているVSCodeの機能Rename Symbolだと、コンポーネントのclass名を変更すると、シンボルの変更をしてくれるだけで、ファイル名、ディレクトリ名の変更は手動で行う必要があります。

WebStormを使う

そこでWebStormを使うと、コンポーネント名の変更が比較的簡単にできることがわかりました。

以下が BookComponent から ComicComponentに変更する模様です。

rename.gif

コンポーネントのclass名を変更するだけで、シンボルを変更するだけでなく、html, scss, spec.ts, tsの全部のファイル名を変更してくれました。
- ディレクトリ名
- selector名

を手動で書き換える必要がありますが、VSCodeで行うときより簡単にできました。

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2