npm - 安装本地模块时忽略 .npmignore

标签 npm

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

此类模块依赖项安装在本地(参见 serverApp/package.json),因此我们不必将整个子模块文件夹包含到最终 rpm 中。我遇到的问题是限制 node_modules 中包含的文件数量.

子模块结构如下所示:

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

添加 .npmignore modules/loader 内的文件由于复制了整个文件夹,因此似乎没有帮助。
modules/loader/tsconfig.json :
{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./dist",
    "strict": true
  }
}
modules/loader/package.json :
{
  "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"
  }
}
serverApp/package.json :
{
  "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"
  }
}

我不确定这是否与我们拥有 .gitignore file 的事实有关。或者因为模块没有在本地发布和安装。

npm 版本 => 5.3.0

编辑

不适用于指定 "files"modules/loader/package.json任何一个

最佳答案

你检查过 node 0.6.13 / npm 1.1.9 ?此问题在 npm 1.1.4 中很常见.
看看这个link

关于npm - 安装本地模块时忽略 .npmignore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48560683/

相关文章:

npm 发布 .gitignored 文件

node.js - 在 npm 中将工件上传到 nexus

node.js - 创建 react 应用程序错误找不到模块 './node'

javascript - package.json 生成/npm 未使用的包

node.js - 使用 npm 安装 Ganache 后权限被拒绝

npm - 使用 nixos 我可以全局安装 nodejs 包吗?

node.js - 我怎样才能做与 Node 中生成的 git 编辑器相同的事情?

node.js - 如何在企业 Web 代理后面设置 Node.js 和 Npm

Angular 8 Peer Dependencies 混淆

node.js - 解决无法建立网络隧道套接字错误