发布到 npm 后,配置改成用 npx 即可,不再需要绝对路径:
json
{
"mcpServers": {
"perf-analyzer": {
"command": "npx",
"args": ["-y", "mcp-perf-analyzer"]
}
}
}
-y 的作用是首次运行时自动确认下载,不需要用户手动交互。
发布前 package.json 需要补充 3 处
1. 加 files 字段(只发布 dist,不带源码)
json
"files": ["dist/", "README.md"]
不加的话会把 src/、node_modules/ 都传上去,体积很大。
2. 加 prepublishOnly 脚本(发布前自动重新构建)
json
"scripts": {
"build": "tsc",
"dev": "tsx src/index.ts",
"start": "node dist/index.js",
"prepublishOnly": "npm run build"
}
3. 补充元信息(让市场页面好看)
json
"keywords": ["mcp", "bundle-analyzer", "performance", "webpack", "vite"],
"author": "你的名字",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/你的用户名/mcp-perf-analyzer"
}
发布流程
csharp
# 1. 登录 npm
npm login
# 2. 检查包名是否被占用
npm view mcp-perf-analyzer
# 3. 发布(会自动触发 prepublishOnly 先构建)
npm publish --access public