LoginSignup
7

More than 5 years have passed since last update.

symlinkで複数モジュールの管理を楽に

Posted at

Node.jsで複数モジュールを扱う場合は、

npm install -g symlink

でインストールできるsymlinkがとっても便利です。

例えばparent/child/grandchildというモジュールがあり、

parent <- child <- grandchild

という依存関係にあった場合、モジュールを配置したディレクトリ上に移動して、

symlink -r .

とするだけ。これだけでparent/child/grandchild全ての依存関係が解決された状態になります。

これをsymlinkを使わずにやろうとすると、全てのモジュールをチェックして依存関係を整理し、依存する順番にnpm linkを実行する必要があります(symlinkはこれをやってくれている)。

cd hoge-parent && npm link
cd ..
cd hoge-child && npm link
cd ..
cd hoge-grandchild && npm link

parent/child/grandchildみたいな依存関係がなくても、全てのモジュールの依存関係をコマンド一つで解決してくれるのはとても便利じゃないかと!

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
7