.npmignore在安装本地模块时被忽略

.npmignore在安装本地模块时被忽略,npm,Npm,我们所有的服务器项目都包含一个git子模块文件夹(比如modules),其中包含我们的自定义模块/组件 这样的模块依赖项是本地安装的(请参见serverApp/package.json),这样我们就不必将整个子模块文件夹包含到最终rpm中。我遇到的问题是限制node\u模块中包含的文件数量 子模块结构如下所示: modules |--loader |--dist => compiled js files here that are created when installing th

我们所有的服务器项目都包含一个git子模块文件夹(比如
modules
),其中包含我们的自定义模块/组件

这样的模块依赖项是本地安装的(请参见
serverApp/package.json
),这样我们就不必将整个子模块文件夹包含到最终rpm中。我遇到的问题是限制
node\u模块中包含的文件数量

子模块结构如下所示:

modules
|--loader
   |--dist => compiled js files here that are created when installing the module
   |--ts => contains typescript files that shouldn't be included in node_modules
   |--package.json
   |--tsconfig.json
|--more modules
|--.gitignore
modules/loader
中添加
.npmignore
文件似乎没有帮助,因为整个文件夹都被复制了

modules/loader/tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./dist",
    "strict": true
  }
}
{
  "name": "loader",
  "version": "1.2.0",
  "private": true,
  "description": "",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "scripts": {
    "preinstall": "npm run build",
    "build": "../../node_modules/typescript/bin/tsc",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "@types/lodash": "^3.9.3",
    "@types/nomnom": "0.0.28",
    "@types/yamljs": "^0.2.30",
    "lodash": "^3.9.3",
    "nomnom": "^1.8.1",
    "yamljs": "^0.2.1"
  },
  "devDependencies": {
    "typescript": "~2.3.4"
  }
}
{
  "name": "my-server-app",
  "version": "2.3.0",
  "description": "",
  "main": "myServerApp.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "license": "private",
  "dependencies": {
    "loader": "file:modules/loader"
  },
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-cli": "^0.1.13"
  }
}
modules/loader/package.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./dist",
    "strict": true
  }
}
{
  "name": "loader",
  "version": "1.2.0",
  "private": true,
  "description": "",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "scripts": {
    "preinstall": "npm run build",
    "build": "../../node_modules/typescript/bin/tsc",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "@types/lodash": "^3.9.3",
    "@types/nomnom": "0.0.28",
    "@types/yamljs": "^0.2.30",
    "lodash": "^3.9.3",
    "nomnom": "^1.8.1",
    "yamljs": "^0.2.1"
  },
  "devDependencies": {
    "typescript": "~2.3.4"
  }
}
{
  "name": "my-server-app",
  "version": "2.3.0",
  "description": "",
  "main": "myServerApp.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "license": "private",
  "dependencies": {
    "loader": "file:modules/loader"
  },
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-cli": "^0.1.13"
  }
}
serverApp/package.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./dist",
    "strict": true
  }
}
{
  "name": "loader",
  "version": "1.2.0",
  "private": true,
  "description": "",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "scripts": {
    "preinstall": "npm run build",
    "build": "../../node_modules/typescript/bin/tsc",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "@types/lodash": "^3.9.3",
    "@types/nomnom": "0.0.28",
    "@types/yamljs": "^0.2.30",
    "lodash": "^3.9.3",
    "nomnom": "^1.8.1",
    "yamljs": "^0.2.1"
  },
  "devDependencies": {
    "typescript": "~2.3.4"
  }
}
{
  "name": "my-server-app",
  "version": "2.3.0",
  "description": "",
  "main": "myServerApp.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "license": "private",
  "dependencies": {
    "loader": "file:modules/loader"
  },
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-cli": "^0.1.13"
  }
}
我不确定这是否与我们有一个或因为模块没有在本地发布和安装的事实有关

npm版本=>5.3.0

编辑


无法在
模块/loader/package.json中指定
“文件”

您是否使用
节点0.6.13/npm 1.1.9进行了检查?此问题在npm 1.1.4中很常见。

查看一下这个

,在检查完问题后,我发现了以下需要指出的有用点:

我们使用一个.npmignore文件来防止您的包中有东西。 如果没有.npmignore文件,但是有.gitignore文件,那么npm将忽略与.gitignore文件匹配的内容

如果要包含被.gitignore文件排除的内容,可以创建一个空的.npmignore文件来覆盖它。 与git一样,npm在包的所有子目录中查找.npmignore.gitignore文件,而不仅仅是根目录

与.gitignore文件类似,npmignore也遵循以下规则

空白行或以#开头的行将被忽略&标准的全局模式可以工作

可以用正斜杠/结束模式以指定目录

您可以通过以感叹号开头来否定模式

默认情况下,将忽略以下路径和文件,因此无需将它们显式添加到.npmignore

此外,节点_模块中的所有内容都将被忽略,捆绑依赖项除外。npm会自动为您处理此问题,因此不必麻烦将节点\ u模块添加到.npmignore

测试您的.npmignore或文件配置是否有效

如果要再次检查包是否只包含发布时要包含的文件,可以在本地运行npm pack命令,该命令将在工作目录中生成tarball,与发布时的方式相同

你也可以在这里签出同样的问题
谢谢。

您提到您不想将“整个子模块”包含在“最终rpm”中,我认为您将最终准备好软件包。我复制了类似的设置,并添加了一个“.npmignore”来忽略我使用
npm install--save./task_in
安装的“子模块”,其中“task_in”是我的模块保存在主包('task')package.json'的旁边

当在“任务”文件夹中使用
npm pack
准备最终包时,我得到了一个没有文件夹('task_in')的包(tar文件),如“.npmignore”中所示

但是,在工作时,我发现模块“task_in”文件夹被复制到“node_modules”中,该模块自动不包含在最终包中(请参阅)。此外,在编写包时,.gitignore被“.npmignore”覆盖


因此,这是我的“两分钱”,我希望它能帮助您。

我没有使用
npm1.1.4
。使用的版本是
5.3.0
。我无法真正更改版本我们没有使用npm pack,但是我们使用grunt创建rpm您如何使用grunt创建rpm?有插件吗?主要是
grunt easy rpm
要配置grunt easy rpm,请尝试使用grunt配置文件中的“excludeFiles”键排除文件,(查找文档-)。但是文件夹甚至在创建rpm之前就已经添加到
node_模块中了。我无法对每个模块中的每个文件夹进行硬编码。问题在于npm。它首先不应该复制文件夹