我想发布一个包含我的源代码和分发文件的 npm 包。我的 GitHub 存储库包含 src
文件夹,其中包含 JavaScript 源文件。构建过程会生成 dist
包含分发文件的文件夹。当然, dist
文件夹没有检入 GitHub 存储库。
我如何发布一个 npm 包,当有人这样做时 npm install
,他们得到 src
以及 dist
文件夹?目前,当我从我的 Git 存储库运行 npm publish
时,只会发布 src
文件夹。
我的 package.json 文件如下所示:
{
"name": "join-js",
"version": "0.0.1",
"homepage": "https://github.com/archfirst/joinjs",
"repository": {
"type": "git",
"url": "https://github.com/archfirst/joinjs.git"
},
"main": "dist/index.js",
"scripts": {
"test": "gulp",
"build": "gulp build",
"prepublish": "npm run build"
},
"dependencies": {
...
},
"devDependencies": {
...
}
}
原文由 Naresh 发布,翻译遵循 CC BY-SA 4.0 许可协议
看一下 package.json 文件的“files”字段: package.json, files
从文档中: