3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ionic-sub CLIに、aliasの自動設定コマンドを追加しました(Ionic v3対応)

Last updated at Posted at 2018-08-07

使い方

$ npm i @rdlabo/ionic-sub -g
$ cd [Ionic Project Directory]
$ ionic-sub set alias

このコマンドを実行すると、Aliasと環境変数の設定を自動的に行います。

Alias

import文に@が使えるようになります。デフォルトの設定では相対パスを書かないといけないので、ファイルを移動したり、コピペしたりすると修正が必要でした。しかし、@を使うと常にsrc/からの相対パスとなりますので、Current Direvtoryを気にする必要がなくなります。

例えば、以下のように書けるようになります。

import { HomePage } from '../pages/home/home';
↓
import { HomePage } from '@/pages/home/home';
import { Example } from '../../../providers/example/example';
↓
import { Example } from '@/providers/example/example';

環境変数

Ionic v3のデフォルトの設定では、--prodをつけた場合とつけていない場合での処理の分岐を行うことができませんが、@app/environmentからのインポートによりそれを可能にします。

import { environment } from '@app/environment';

console.log(environment)

もし、--prodがついていれば、environment/environment.prod.tsからインポートを行います。ついていなければ、environment/environment.dev.tsからインポートを行います。デフォルトファイルを用意しておりますので、お試しください。

その他

Ionic-sub CLIをつくった経緯はこちらです。
また、他のコマンドについて https://github.com/rdlabo/ionic-sub をご覧ください。Starいただけると励みになります。また、ドキュメントつくってくださる方募集中。

3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?