What's the process for releasing an npm package with both source and distribution files?

I’m trying to put out an npm package that includes my original code and the final output files. My project has a source folder with the main JavaScript files. When I build it, it creates an output folder with the final files. The output folder isn’t in my GitHub repo.

I want to know how to publish this package so that when someone runs npm install, they get both the source and output folders. Right now, when I use npm publish from my Git repo, it only uploads the source folder.

Here’s what my package.json looks like:

{
  "name": "code-combine",
  "version": "1.0.0",
  "homepage": "https://github.com/myusername/code-combine",
  "repository": {
    "type": "git",
    "url": "https://github.com/myusername/code-combine.git"
  },
  "main": "output/main.js",
  "scripts": {
    "test": "check",
    "build": "check build",
    "prepublish": "npm run build"
  },
  "dependencies": {},
  "devDependencies": {}
}

Any ideas on how to make this work?

yo charlotte, had the same issue. try adding a .npmignore file to ur project. it overrides .gitignore for npm publishing. just list the files/folders u want to include, like:

!output/

this’ll make sure ur output folder gets published. dont forget to run ur build script b4 publishing tho!

To publish both source and distribution files, you’ll need to modify your npm publishing process. First, ensure your build script generates the output folder correctly. Then, update your package.json to include a ‘files’ array specifying both ‘source’ and ‘output’ directories. This tells npm which files to include during publication.

Additionally, consider using a .npmignore file to fine-tune what gets published. This can override your .gitignore settings for npm specifically. Remember to run your build script before publishing to ensure the latest output files are included.

Lastly, double-check that your main field in package.json points to the correct entry point in your output folder. This ensures users can properly import your package.

Hey there! I’ve dealt with this exact issue before. The key is to use the files field in your package.json. This tells npm which files and directories to include when publishing.

For your case, you’d want to add something like this to your package.json:

"files": [
  "source",
  "output"
]

This ensures both your source and output directories get published. Also, make sure your .gitignore isn’t excluding the output folder from git - that can cause issues with npm publish.

One more thing: your prepublish script is great, but consider using prepublishOnly instead. It only runs when you actually publish, not on every install.

Hope this helps! Let me know if you run into any snags.