简体   繁体   English

package.json-如何确定模块的哪些部分已安装

[英]package.json - how to determine what parts of the module are installed

I have a project structure like this: 我有一个这样的项目结构:

__tests__
example
src
.bablerc
.eslintignore
.eslintrd
.gitignore
package.json
package-lock.json
README.md

and package.json parameters like: package.json参数,例如:

{
  "name": "",
  "version": "0.0.1",
  "description": "",
  "main": "src/index.js",
  "scripts": {
    "test": "jest"
  },
  "files": [
    "src/"
  ],
  "repository": {
    "type": "git",
    "url": "url"
  },
  "jest": {
  },
  "devDependencies": {
  },
  "peerDependencies": {
  }
}

When I npm install this modules I only get src folder with an empty index.js file. 当我npm install此模块时,我只会得到带有空index.js文件的src文件夹。 The goal was to only have the user install all of the src folder and not the example part since that is an example app. 目标是仅让用户安装所有src文件夹,而不安装example部分,因为那是示例应用程序。 I thought that "files": ["src/"], would solve this. 我认为"files": ["src/"],将解决此问题。 However it's not doing what I would expect. 但是,它没有达到我的期望。 I don't see anything that is in the src folder. 我看不到src文件夹中的任何内容。 It's empty! 它是空的!

npm docs say: npm文档说:

The optional files field is an array of file patterns that describes the entries to be included when your package is installed as a dependency. 可选文件字段是文件模式的数组,描述了将软件包作为依赖项安装时要包括的条目。 File patterns follow a similar syntax to .gitignore, but reversed: including a file, directory, or glob pattern (*, **/ , and such) will make it so that file is included in the tarball when it's packed. 文件模式遵循与.gitignore类似的语法,但是相反:包括文件,目录或全局模式(*,** / 等)将使文件模式成为打包文件时包含在tarball中。 Omitting the field will make it default to [" "], which means it will include all file 省略该字段将使其默认为[“ ”],这意味着它将包括所有文件

How do I allow the user to install all of the src folder and ignore the example folder? 如何允许用户安装所有src文件夹并忽略示例文件夹?

I'm on npm 5.6.0 and node v9.11.2 我在npm 5.6.0和节点v9.11.2

Almost there! 快好了! Files entry behave like in a line a .gitignore . 文件条目的行为类似于.gitignore行。 That works: 这样可行:

"files": ["src"]

For testing purposes, you can run npm pack --dry-run to check in the pack reports what files would be included when running npm install on the package you're developing. 出于测试目的,您可以运行npm pack --dry-run以在包报告中检查在要开发的软件包上运行npm install时将包括哪些文件。

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

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