1
0

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 3 years have passed since last update.

npmパッケージ開発中にyarn addしても変更が反映されない場合はyarnのキャッシュに注意

Posted at

npmパッケージはnpmに公開しなくても、npm packすればパッケージ(tgz)を生成してくれる。
そしてできたtgzのパスをyarn addの引数に指定すれば、ふだんライブラリをインストールするような形で追加されてくれる。(たぶんnpm installでも同じなはず)

$ cd [developing-peoject-root]
$ npm run build
$ npm pack # プロジェクトルートに[package-name]-[version].tgzが生成される
$ cd [test-project-root]
$ yarn add [your-tgz-path]

何か修正して再度npm packした際は、yarn addする前にyarn cache cleanする必要がある。
(ちなみに変更がtgzに反映されているかどうかはtgzを解凍すればわかる)

$ cd [developing-peoject-root]
$ npm run build
$ npm pack  # 変更を加えたtgzが生成される
$ cd [test-project-root]
$ yarn cache clean # これをしないと、yarnがキャッシュしたバージョンを再度インストールするので変更が反映されない
$ # ちなみに一度yarn removeする必要はなさそう
$ yarn add [your-tgz-path]

余談だが、yarnのドキュメントにはyarn cache clean [<module_name...>]で指定したパッケージだけのcleanができるように書いてあるが、何か間違っているのか、これでは次のyarn addで前のバージョンがインストールされてしまった。
何か凡ミスをしてる気もするが、いまのところとりあえずyarn cache cleanを使っている。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?