如何发布带有分发文件的 npm 包? [英] How to publish an npm package with distribution files?
问题描述
我想发布一个包含我的源代码和分发文件的 npm 包.我的 Github 存储库包含 src
文件夹,其中包含 JavaScript 源文件.构建过程生成包含分发文件的 dist
文件夹.当然,dist
文件夹没有签入 Github 仓库.
I would like to publish a npm package that contains my source as well as distribution files. My Github repository contains src
folder which contains JavaScript source files. The build process generates dist
folder that contains the distribution files. Of course, the dist
folder is not checked into the Github repository.
我如何发布 npm 包,当有人执行 npm install
时,他们会获得 src
以及 dist
文件夹?目前,当我从 git 存储库运行 npm publish
时,它只会发布 src
文件夹.
How do I publish a npm package in a way that when someone does npm install
, they get src
as well as dist
folder? Currently when I run npm publish
from my git repository, it results in only src
folder being published.
我的 package.json 看起来像这样:
My package.json looks like this:
{
"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": {
...
}
}
推荐答案
查看 package.json 文件的files"字段https://docs.npmjs.com/files/package.json#files
Take a look at the "files" field of package.json file https://docs.npmjs.com/files/package.json#files
来自文档:
文件"字段是要包含在项目中的文件数组.如果您在数组中命名一个文件夹,那么它也将包含该文件夹中的文件.(除非它们会被另一条规则忽略.)
The "files" field is an array of files to include in your project. If you name a folder in the array, then it will also include the files inside that folder. (Unless they would be ignored by another rule.)
这篇关于如何发布带有分发文件的 npm 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!