简体   繁体   English

如何为本地引用的节点模块指定node_modules文件夹

[英]How to specify node_modules folder for locally referenced node module

We need to specify node_modules folder for locally referenced node module that resides in an external folder relative to the current application folder. 我们需要为本地引用的节点模块指定node_modules文件夹,该模块位于相对于当前应用程序文件夹的外部文件夹中。

We have a scenario where we are referencing an external common module's js files within another client-side app, however the same node modules being references in both are being duplicated in the final build. 我们有一个场景,其中我们在另一个客户端应用程序中引用了外部公共模块的js文件,但是在最终版本中都复制了两个相同的节点模块。 we have tried using webpack.optimize.DedupePlugin() without any success. 我们尝试使用webpack.optimize.DedupePlugin()失败。

The directory structure is as follows: 目录结构如下:

  1. We have a private npm module on the local disk called 'common', and then we have our project folder called 'app'. 我们在本地磁盘上有一个名为“ common”的私有npm模块,然后我们的项目文件夹为“ app”。
  2. Both folders are on the same level in directory structure & are under the same root. 这两个文件夹在目录结构中处于同一级别,并且位于同一根目录下。
  3. The 'app' itself is a npm module & has a package.json file with its own node_modules folder. “ app”本身是一个npm模块,并具有一个package.json文件及其自己的node_modules文件夹。 |—root |— common/node_modules |— app/node_modules We want to specify via configuration either via npm or web pack a way for the app to resolve references from its specified path of node_modules and not to refer to any other node_modules location including the one in common module. |—root |— common/node_modules |— app/node_modules我们想通过npm或Web pack通过配置指定一种方法,使该应用可以从其指定的node_modules路径解析引用,而不是引用任何其他node_modules位置,包括一个通用模块。

You can use npm link or just a simple symlink. 您可以使用npm链接或仅使用一个简单的符号链接。 Do something like that: 做这样的事情:

cd root/app (your app directory)
npm link ../common

OR 要么

cd root/app (your app directory)
ln -s ../common node_modules/common

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

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