LoginSignup
8
0

More than 5 years have passed since last update.

npm packageの公開手順

Posted at

公開するまでのフローを知りたかったので、お試ししてみました。

アカウントの登録

パッケージの公開にはアカウントが必要なので サインアップ します。

1.png

太字の項目は次のフェーズで利用します。

① 名前
メールアドレス
ユーザー名
パスワード
⑤ メルマガの購読をするかどうか
⑥ 規約とプライバシーポリシーの同意

アカウントの設定

取得したアカウントをマシンに設定します。

$ npm adduser

アカウントの作成 時に登録した、ユーザー名・パスワード・メールアドレスの内容を入力します。

Username: ユーザー名
Password: パスワード
Email: (this IS public) メールアドレス

問題なく終わるとこんな感じです。(問題があったらどうなるのかはわからない)

Logged in as ここにユーザー名 on https://registry.npmjs.org/.

package.jsonの作成

すでにpackage.jsonがある場合は必要ありません。
今回はお試しなので、ユーザー名をネームスペースとした Scoped Packages として作成します。

$ npm init --scope=ここにユーザー名

対話で入力していく際に package name として設定したものが、公開されるpackage名になります。

package.json
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (@niar/reg-npm)
version: (1.0.0) 0.0.1
description:
entry point: (index.js)
test command:
git repository:
keywords:
author: Yuta Nakano
license: (ISC) MIT
About to write to Your/reg-npm/package.json:

{
  "name": "@niar/reg-npm",
  "version": "0.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Yuta Nakano",
  "license": "MIT"
}


Is this ok? (yes)

公開

内容がなくても公開できちゃうので公開します。
(Scoped Packagesで公開する為 --access=public を付与しています)

$ npm publish --access=public
+ @niar/reg-npm@0.0.1

4.png

参考

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