是否有package.json选项来指定node_modules目录的相对位置?
对于我的应用程序,我有一个如下所示的目录结构。
当前目录结构
root/
---/client
-------/(client code)
---/server
------/package.json* (sibling of node_modules)
------/node_modules*
------/server.js
我想添加grunt任务到项目的根目录(因为它们将应用于客户端代码和服务器代码)。 Gruntfile.js 需要是 sibling of package.json .
出于这个原因,我想将 package.json 移动到根目录,但我也想将 node_modules 保留在服务器目录中。 package.json 中是否有选项可以执行此操作?
我希望生成的目录结构如下所示。
首选目录结构
root/
---/package.json* (not a sibling of node_modules)
---/Gruntfile.js
---/client
-------/(client code)
---/server
------/node_modules*
像下面这样的选项是最优选的(npm docs 中似乎没有这样的选项)
假设的package.json
{
"output_dir": "server/node_modules", // Something like this
"dependencies": { ... },
"devDependencies": { ... }
}
最佳答案
您可以使用 CLI 上的前缀选项来完成此操作。
npm install express --prefix ./server/node_modules
不知道 package.json 中是否存在类似选项
关于javascript - 如何更改 package.json 输出位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22445410/