简体   繁体   English

Webpack似乎将node_modules的node_modules包括在包中?

[英]Webpack seems to be including node_modules of node_modules into bundle?

So I have recently discovered that webpack seems to be including node_modules dependencies inside my top level node_modules dir into my actual bundle. 因此,最近我发现Webpack似乎在我的顶级node_modules目录中的实际包中包含了node_modules依赖项。 For example, one dependency, example-dep depends on lodash, and so has a node_modules dir inside node_modules/example-dep , with lodash inside. 例如,一个依赖关系, example-dep取决于lodash,因此在node_modules/example-dep内也有一个node_modules目录,在lodash内。 Because example-dep imports one method from lodash, for some reason the entire lodash library is getting thrown into my bundle. 因为example-dep从lodash导入了一个方法,所以由于某种原因,整个lodash库都被扔进了我的包中。

How can I fix this? 我怎样才能解决这个问题? Why are there nested node_module dirs inside my dependencies anyways? 为什么我的依赖项中仍然有嵌套的node_module dirs? It's not like I am building those projects and trying to contribute to them, I literally just do npm install example-dir . 并不是说我正在构建那些项目并试图为它们做贡献,我实际上只是做npm install example-dir

Those node_modules directories are installed because are listed as devDependencies of the package (in case you want to build yourself or test). 安装了那些node_modules目录,因为它们被列为软件包的devDependencies (以防您自己构建或测试)。 To install solely the built file 仅安装生成的文件

npm install --production <package> 

or better 或更好

npm install --only=prod

For more details check https://docs.npmjs.com/cli/install . 有关更多详细信息,请检查https://docs.npmjs.com/cli/install

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

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