How do I generate a separate package.json file in the dist directory?

Viewed 2278

I'm creating a package to publish to npm.

  1. Can someone please help how do I generate separate package.json and place it to dist directory? I'm using gulp as build tool.
  2. What should be the contents of the package.json that is meant to be published? I believe we need to exclude devdependencies. I'm not sure about others.

Please help.

2 Answers

You should have a single package.json for your project, and it's meant to be published on NPM. The idea with devDependencies is that they won't get installed when people install your package from NPM, as opposed to dependencies, which do get installed.

For your package to work as expected, you need at least the main field that points to your main JS file.

See the docs for package.json for a list of available fields.

You should use package.json in your directory.

Publish file you want with files of package.json,

choose your main file (file will call by require) with main of package.json

You should read npm package.json

Example: (dist is directory build by gulp)

{
    "name": "<your_module>",
    "files": [
        "dist",
        "someFile.js"
    ],
    "main": "dist/index.js",
    ...
}

With this way, you should add module build your module to devDependencies, module was called by your module in dependencies

Related