如何发布带有分发文件的npm软件包? [英] How to publish a npm package with distribution files?

查看:105
本文介绍了如何发布带有分发文件的npm软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发布一个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文件的文件"字段 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆