gruntみたいなコマンド実行できるnodeのmoduleをpackage.jsonに書いた時のメモ
前回の記事でpackage.jsonのdevDependenciesに依存関係は書いたんだけど そういえばgruntとかコマンド打って動かす系のnode moduleって普通は-gつけてglobal installするよなーとか思って
案の定、別の環境で前回のpackage.jsonからnpm installしたらコマンドは打てないし、なんかイイ方法ないのかなーとか思ってたらそんな感じのがstackoverflowにあった
// package.json
"scripts": {
"preinstall": "npm i -g themodule"
}
(via. Install dependencies globally and locally using package.json)
npmにも書いてあった
要するに"preinstall"にベタでコマンドを書いておけばmoduleはインストールされる
gruntでいうと
// package.json@tt.js
"scripts": {
"preinstall": "npm i -g grunt-cli"
}
みたいな感じかな
grunt-cliをinstallすれば、gruntコマンドを打つことでlocalのnode_modules/gruntを見に行ってくれる
そのlocalのnode_modules/gruntはdevDependenciesでパッケージ管理されているという寸法
あと前回は npm install -g grunt しちゃったんだけど、0.4.0からはgrunt-cliをinstallすべきなのを見落としてた