简体   繁体   English

NodeJS:如何在不同目录中使用package.json和node_modules

[英]NodeJS: how to use package.json and node_modules in different directories

I have an app using the file structure 我有一个使用文件结构的应用程序

package.json
src/main/
 - webapp
 - java (containing my API)

My API is restricted so that it can only dispatch files from within src/main/webapp , as a result I need my node_modules to install within that folder. 我的API受限制,因此它只能从src/main/webapp内分发文件,因此我需要将node_modules安装在该文件夹中。

If I run npm install I get the following: 如果我运行npm install得到以下信息:

package.json
node_modules/
src/main/
 - webapp
 - java (containing my API)

Is there a way I can change this so it installs by default in the following structure? 有什么办法可以更改此设置,使其默认安装在以下结构中?

package.json
src/main/
 - webapp
    - node_modules/
 - java (containing my API)

If possible I'd rather not have a global environment variable as I work on multiple apps on this machine and I don't want them all installing to this apps node_modules 如果可能的话,我宁愿没有全局环境变量,因为我在这台机器上处理多个应用程序,并且我不希望它们都安装到该应用程序中node_modules

For the case above I intended to install my webapp dependencies, such as AngularJS using NodeJS. 对于上述情况,我打算安装我的webapp依赖项,例如使用NodeJS的AngularJS。 It turns out there is another package manager Bower that is much more fit for this purpose and allows you to configure the location of its bower_components to wherever you like. 事实证明,还有另一个软件包管理器Bower更适合于此目的,它允许您将bower_components的位置配置为bower_components位置。 This has solved my issue and I now have the following file structure 这已经解决了我的问题,我现在具有以下文件结构

package.json
node_modules/
src/main/
 - webapp
    -bower_components
        -angular (etc) 
 - java (containing my API)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM