简体   繁体   English

如何在dist目录中生成单独的package.json文件?

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

I'm creating a package to publish to npm. 我正在创建一个要发布到npm的程序包。

  1. Can someone please help how do I generate separate package.json and place it to dist directory? 有人可以帮我如何生成单独的package.json并将其放置到dist目录吗? I'm using gulp as build tool. 我正在使用gulp作为构建工具。
  2. What should be the contents of the package.json that is meant to be published? 应该发布的package.json的内容应该是什么? 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. 您应该为您的项目创建一个package.json文件,并将其发布在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. 有这个想法devDependencies是,他们将不会安装,当人们从NPM安装你的包,而不是dependencies ,这做得到安装。

For your package to work as expected, you need at least the main field that points to your main JS file. 为了使程序包按预期工作,至少需要指向主JS文件的main字段。

See the docs for package.json for a list of available fields. 有关可用字段的列表,请参阅package.json的文档

You should use package.json in your directory. 您应该在目录中使用package.json

Publish file you want with files of package.json , 使用package.json files发布所需的文件,

choose your main file (file will call by require ) with main of package.json 选择您的主文件(文件将被调用require用) mainpackage.json

You should read npm package.json 您应该阅读npm package.json

Example: ( dist is directory build by gulp ) 示例:( dist是由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 这样,您应该将模块构建your module添加到devDependenciesyour moduledependencies被模块调用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 package.json 与单独的文件(在本例中为 nodemon.app)链接 - How do I link package.json with a separate file (in this case nodemon.app) 如何在没有脚本部分的情况下将 package.json 复制到 dist 文件夹 - How to copy package.json to dist folder without the scripts part 如何向运行 javascript 文件的 package.json 文件添加自定义脚本? - How do I add a custom script to my package.json file that runs a javascript file? 如何自动更新 package.json 中的条目? - How do I update the entries in package.json automatically? 如何告诉Prettier忽略package.json文件? - How can I tell Prettier to ignore a package.json file? package.json 中的根目录 - Root directory in package.json ENOENT:没有这样的文件或目录,打开 'C:\Users\subwo\package.json' - ENOENT: no such file or directory, open 'C:\Users\subwo\package.json' React Js:没有那个文件或目录,打开Package.json - React Js : no such file or directory, open Package.json 如何在package.json中的项目目录中为gulp文件创建路径 - How to make a path for gulp file in project's directory in package.json 如何在没有 package.json 文件的情况下运行 JavaScript 项目,从而在运行时出错? - How do I run a JavaScript project with no package.json file present, which therefore gives error when running it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM