简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM