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

物理キーなしでnpmjsにパッケージを公開する

0
Posted at

大まかなやること:

  • npmjsで、きめ細かなアクセストークンを作成する
  • 作成したトークンを .npmrc ファイルに書く
  • npm publishコマンドでパッケージをリリースする

きめ細かなアクセストークンを作成する

  • https://www.npmjs.com/ でアカウントにログインする
  • 右上のアバターから Access Tokens をクリックする
  • 表の右上にある緑の Generate New Token ボタンをクリックする
  • パスワードを求められるので入力する
  • 何でも良いので適当な Token name を付ける
  • Bypass two-factor authentication (2FA) にチェックを入れる
  • (個人アカウントの場合) Packages and scopes の Permissions を Read and write に設定し、 All packages を選択する
  • ※デフォルトでは7日でトークンが削除される。変更する場合は Expiration Date の値を変更する
  • Generate token ボタンをクリックする
  • トークンを作成したら緑枠内に表示される npm_ から始まるトークンをコピーする(作成したトークンは初回のみ表示される)

作成したトークンを .npmrc ファイルに書く

.npmrcファイルを作成し、次の文字列の npm_xxxxx の部分を作成したトークンに置き換えたものをファイルに記述する:

//registry.npmjs.org/:_authToken=npm_xxxxx

  • npmパッケージに.npmrcファイルが含まれないよう、.npmignoreファイルに .npmrc を記述する。
  • gitを使っている場合は、ファイルがgitで管理されないよう、 .gitignore ファイルに .npmrc を記述する。

npmパッケージをリリースする

package.jsonなどの設定が整っていることを確認し、
npm publish コマンドでnpmパッケージをリリースする。
npmのCLIがアカウントにログインされていない場合は、
リリースする前に npm adduser コマンドでログインする必要がある。

フォークしたリポジトリを自分のバージョンとして公開する場合

自分の場合、フォークしたリポジトリを自分のバージョンとして公開したかったので、
package.jsonのnameをスコープ付き(例: @Densyakun/react-full-height)に変更し、
npm publish コマンドの代わりに、 npm publish --access public コマンドを使う。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?