【发布时间】:2016-01-03 17:58:03
【问题描述】:
我的项目中有一个 package.json 文件,其中包含大约 20 个依赖项。当我这样做时
npm install
它将所有依赖项和子依赖项放在最顶层的 node_modules 目录中。它包含数百个模块,而它应该只有我的 20 个。子依赖项应该在我的主要依赖项下的 node_module 目录中,但它创建了一个扁平结构。
我在 Ubuntu 14.04 上使用 npm 3.5.4 和节点 0.10.41
谁能帮助我按照正确的树结构安装模块?
编辑----- 添加我的 packages.json 文件:
{
"name": "lms",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC",
"dependencies": {
"aliasify": "^1.8.0",
"angular": "^1.4.7",
"angular-animate": "^1.4.7",
"angular-aria": "^1.4.7",
"angular-material": "^0.11.4",
"angular-resource": "^1.4.7",
"angular-ui-router": "^0.2.15",
"angular-ui-sortable": "^0.13.4",
"backbone": "^1.2.3",
"bootstrap": "^3.3.5",
"browser-sync": "^2.9.12",
"browserify": "^12.0.1",
"browserify-ngannotate": "^1.0.1",
"del": "^2.1.0",
"eslint": "^1.8.0",
"eslint-config-defaults": "^7.1.1",
"font-awesome": "^4.5.0",
"gulp": "^3.9.0",
"gulp-clean": "^0.3.1",
"gulp-concat": "^2.6.0",
"gulp-connect": "^2.2.0",
"gulp-connect-php": "0.0.7",
"gulp-eslint": "^1.1.1",
"gulp-minify-css": "^1.2.1",
"gulp-ng-annotate": "^1.1.0",
"gulp-open": "^1.0.0",
"gulp-sass": "^2.1.0",
"gulp-uglify": "^1.4.2",
"jquery": "^2.1.4",
"jquery-ui": "^1.10.5",
"lodash": "^3.10.1",
"merge-stream": "^1.0.0",
"ng-backbone": "file:local_node_modules/ng-backbone",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
},
"browserify": {
"transform": [
"aliasify"
]
},
"aliasify": {
"aliases": {
"underscore": "lodash"
}
}
}
【问题讨论】:
-
你的程序还能用吗?
-
@Manu,是的,该程序仍然有效。但是在一个目录中处理数百个文件是很麻烦的。阅读代码时很难找到东西。
-
你能告诉我们你的
package.json吗?! -
@marcel,添加了 packages.json 文件的内容。
-
我认为 NPM 这样做是为了优化 - 特别是当多个模块共享依赖项时它会有所帮助。
标签: javascript linux node.js npm