Skip to content

发布 npm 包

使用pnpm publish发布包到 npm 仓库

sh
pnpm publish --tag 1.0.0 --access public --registry https://registry.npmjs.org

发布脚本

js
const path = require('node:path')
const chalk = require('chalk')
const execa = require('execa')
const args = require('minimist')(process.argv.slice(2))

const targetVersion = args.v

const step = msg => console.log(chalk.cyan(msg))

const run = (bin, args, opts = {}) => execa(bin, args, { stdio: 'inherit', ...opts });

(async function main() {
  step('\nPublishing package...')

  await run(
    'pnpm',
    [
      'publish',
      '--tag',
      targetVersion,
      '--registry',
      'https://registry.npmjs.org',
      '--access',
      'public',
    ],
    {
      cwd: path.resolve(__dirname),
      stdio: 'pipe',
    },
  )
})()