LoginSignup
0
0

Yarn v2でGithub Packages npm registryからyarn addする方法

Posted at

はじめに

Yarn v2でGithub Packagesのprivateなnpm registryからyarn addをする方法です。
Yarn v4にアップデートしてGithub Packagesからyarn addをしなくてはならなかったため記事を書きました。
Yarn v1からYarn v2にアップデートし、アーキテクチャが刷新され.npmrcが読み込まれなくなったため新たな設定が必要になったぽいです。

結論

.yarnrc.ymlに下記のSettingsを追加する。

npmScopes:
  my-scope:
    npmRegistryServer: "https://npm.pkg.github.com"
    npmAuthToken: ${YOUR_TOKEN_HERE}

内容

npmの場合、.npmrcに下記の様に設定していたと思う。

@MYSCOPE:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${YOUR_TOKEN_HERE}

だが、Yarn v2以降アーキテクチャが刷新され.npmrcではなく.yarnrc.ymlを読み込む様になったと思われる。

なのでこちらを参考に.yarnrc.ymlに設定をする。

npmScopes:
  my-scope:
    npmRegistryServer: "https://npm.pkg.github.com"
    npmAuthToken: ${YOUR_TOKEN_HERE}
  • my-scopeにAddしたいPackagesのNAMESPACEを入れる
  • もし環境変数を特定のファイルから使用したい場合は下記を追加する
injectEnvironmentFiles: [
".my-env",
".my-local-env?",
]

最後に

間違いや指摘等があればぜひよろしくお願いします。

参考文献

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