1.0.0 • Published 3 years ago

small-deploy-endw09 v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

NPM デプロイ

手順

<1.インストール>

cd tiny-npm-deploy
npm init -y
npm install typescript express
npm install @types/express
npx tsc --init

// tsconfig.json編集
    "declaration": true,
    "outDir": "./dist",


// package.json編集
  "scripts": {
    "build": "tsc"
  },

// distフォルダ生成を確認するテスト
npm run build

< 2.確認>

  1. package.json の"name": "tiny-npm-deployxxxxxxx", が npmjs.com で検索してユニークであること

  2. デプロイするファイルを決める => package.json の files に指定(dist すべて)

  "files": [
    "dist"
  ],
  1. dependencies と devDependencies を分ける ※package.json

既に build 時に実行されている@types/express と typescript を dev に移す

  "dependencies": {
    "express": "^4.17.1"
  },
  "devDependencies": {
    "@types/express": "^4.17.11",
    "typescript": "^4.2.4"
  }
  1. package を public アクセス開放 => package.json 編集
  "publishConfig": {
    "access": "public"
  },
  1. CLI ビルド時に実行される file を決める
// package.jsonに追記
  "bin": "dist/index.js",

// index.ts の冒頭に追記 ※直接実行可能とする指定
#!/usr/bin/env node
  1. prePublish スクリプト追加 => package.json の scripts に prepublishOnly 追加 ※publish 前に npm で自動実行される
  "scripts": {
    "build": "tsc",
    "prepublishOnly": "npm run build"
  },
  1. commit to git
git init

// .gitignoreファイル作成
dist
node_modules

git status
git add .
git commit -m "initial commit"
  1. npm publish を実行 ※npm run publish ではない
npm login
npm publish