IntelliJ IDEA / WebStorm で Grunt Task を(かんたんに)実行したい
2013年時点でのやりかたをまとめて下さっている方もいますが、この時点ではタスクごとに設定を追加するというもののようで、なんだかめんどくさそうです。
ですが、ドキュメントを眺めていると、どうやら現在のバージョンでは、Gruntfileからタスクを列挙してくれ、面倒な下準備はほとんどなしにIDE上で実行することができるようです。
A number of tools are started through Node.js, for example, the CoffeeScript, TypeScript, and LESS transpilers, YUI, UglifyJS, and Closure compressors, Karma test runner, Grunt task runner, etc. The Node Package Manager (npm) is the easiest way to install these tools, the more so that you have to install Node.js anyway.
試してみたのでメモ。
環境
- Windows 7 Professional SP1 64bit
- IntelliJ IDEA
- Ultimate Edition 13.1.5
- NodeJS Plugin 135.1141
- NodeJS 0.10.33
- grunt 0.4.5
- grunt-cli 0.1.13
インストール
Using Grunt Task Runnerの通りに進めればOKでした。
NodeJS
僕はWindowsユーザーなので、nodistを使いました。
>nodist -v 0.5.2 >node -v v0.10.33 >npm -v 1.4.6
Grunt
grunt-cli
grunt-cli
をGlobalで入れます。
npm install -g grunt-cli
grunt
grunt
をプロジェクトローカルで入れます。
npm install grunt
NodeJS Plugin
Settings > Plugins > Install JetBrains plugin... よりNodeJSプラグインをインストールします。
設定
Settings > Node.js and NPM よりNodeJSのバイナリ(node.exe)を指定します。正しいバイナリを選択すると、その下の「Version」にNodeJSのバージョンが入ります。
僕はnodistを使用しているのでC:\nodist\v\0.10.33\node.exe
の使用したいバージョンのものを選びました。
使い方
プロジェクト内にGruntfile.js
またはGruntfile.coffee
を配置
Tools > Open Grunt Console
実行したいタスクをダブルクリック
以上でIDEA上でGrunt Taskを実行できました。