How to publish a npm package with distribution files?

Naresh picture Naresh · Jul 27, 2015 · Viewed 85.7k times · Source

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.

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.

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": {
    ...
  }
}

Answer

topheman picture topheman · Jul 27, 2015

When you npm publish, if you don't have an .npmignore file, npm will use your .gitignore file (in your case you excluded the dist folder).

To solve your problem, create a .npmignore file based on your .gitignore file, without ignoring the dist folder.

Soure : https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package