How to publish npm package with distribution files?

I would like to publish an npm package containing my source as well as distribution files. My Github repository contains the src folder that contains the JavaScript source files. The build process creates a dist folder containing distribution files. Of course, the dist folder is not checked in the Github repository.

How to publish npm package in such 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 only results in src publishing.

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": { ... } } 
+50
git github npm
Jul 26 '15 at 10:14
source share
2 answers

Take a look at the "files" field of package.json file https://docs.npmjs.com/files/package.json

From the documentation:

The β€œfiles” field is an array of files to include in your project. If you specify a folder in the array, then it will also contain files inside this folder. (Unless they are ignored by another rule.)

+36
Jul 26 '15 at 22:33
source share

When you npm publish , if you do not have a .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 .

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

+68
Jul 26 '15 at 10:24
source share



All Articles