6
6

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.

IntelliJ IDEAでのDartの作業環境を整える

Last updated at Posted at 2014-10-25

結構やることあったのでまとめておきます。
入れた後で言うのもなんですがDartEditorで十分な気がします。

Dartのインストール(Homebrewから)

$ brew tap dart-lang/dart
$ brew install dart
$ brew install dartium

Intellijで起動すればいいだけなのでbrew linkappsはしません。
普段使うのには推奨されていないですし/Applicationsにいれるのは邪魔になることのほうが多そうです。

Stagehandを入れる

Stagehandを入れます。
これがないとプロジェクトの雛形を作れないので必須です。

$ pub global activate stagehand

ホームディレクトリに.pub-chacheができているのでパスを通します。
export PATH="export PATH=$PATH:$HOME/.pub-cache/bin"

stagehand -o <app_name> webappといった感じで作れるようになります。

Dart Pluginのインストール

ここからIntelliJでの作業になります。

とりあえずstagehandで何かしらプロジェクト作ってそれを開いた状態で作業すると楽だと思います。
PreferenceのPluginからDartをインストールして再起動します。
再起動後、PreferenceのDartの項目にSDKとDartiumのパスを入れます。
homebrewから入れた場合だと

  • Dart SDK Path: /usr/local/opt/dart/libexec
  • Dartium Path: /usr/local/opt/dartium/Chromium.app

で通ると思います。
下のほうに今開いているプロジェクトが表示されているはずなのでついでにチェックを入れておきます。

デバッガの設定

Run > Edit Configurationsから+を押してJavaScript Debugを選択します。
Nameはなんでもいいです。空だとUnnamedに。
URLはhttp://localhost:9000/とか入れておきます。
pub serveのデフォルトポートは8080ですがsudoしないと使えないので適当に9000とかにしてます。 気のせいでした、sudoが必要なのは80番です。
BrowserはもちろんDartiumです。

設定したら一度実行します。
CLI上で$ pub serve --port 9000した後にデバッグ実行してください。
Dartiumが起動してページが表示されたら成功です。

このときエクステンションのインストールが求められると思います(確かそうだったはず・・・)ので誘導に従います。
されなかった場合はストアからjetbrainsと検索してJetBrains IDE Supportを入れます。
これでエラーが起きた場合もIDEでのデバッグが可能になります。

その他

Angularとかやる場合、チュートリアルにある説明通りにやろうとするとpub serveでエラーがでて試すことすらできないと思います。
その場合、pubspec.yamlを少し変更する必要があります。

transformers:
- angular:
    dart_sdk: "/usr/local/opt/dart/libexec"

- angular:と末尾にコロンをつけること
dart_sdkの行の追加です、スペース4個いれてください。

10/29 追記: 毎回書くのめんどくさかったんでシンボリックリンクはりました。

$ cd /usr/local/opt/dart/libexec/bin
$ ln -s ../lib lib
$ ll
total 20408
-rwxr-xr-x  1 tsuguya  wheel  10421264 10 14 22:58 dart*
-rwxr-xr-x  1 tsuguya  wheel      1942 10 14 22:58 dart2js*
-rwxr-xr-x  1 tsuguya  wheel       945 10 14 22:58 dartanalyzer*
-rwxr-xr-x  1 tsuguya  wheel      1538 10 14 22:58 dartfmt*
-rwxr-xr-x  1 tsuguya  wheel      1086 10 14 22:58 docgen*
lrwxr-xr-x  1 tsuguya  wheel         6 10 29 02:34 lib@ -> ../lib
-rwxr-xr-x  1 tsuguya  wheel      1190 10 14 22:58 pub*
drwxr-xr-x  8 tsuguya  wheel       272 10 14 22:58 snapshots/

怒られなくなったのでとりあえずよしとします。



DartEditorだとpubspec.yamlが簡単に編集できて楽なので完全に離れられるかどうか・・・。

6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?