我们所有的服务器项目都包含一个 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/