简体   繁体   English

Javascript:package.json 依赖项是否包含在构建中,如果它没有在任何地方导入?

[英]Javascript: is package.json dependency included in build, if it's not imported anywhere?

In project, there is some dependency package (npm install [some-name] --save) listed in package.json file, but not imported in any of my ES6 module files in source code.在项目中,package.json 文件中列出了一些依赖项 package (npm install [some-name] --save),但未在我的任何模块文件中导入的代码源代码。 Will this package be included in final build (ex. rollup output)?这个 package 是否会包含在最终版本中(例如汇总输出)?

As far as I understand, not imported es6 module can't even provide any side effects, so bundler (ex. rollup, webpack) doesn't have it in dependency graph.据我了解,未导入的 es6 模块甚至无法提供任何副作用,因此捆绑程序(例如 rollup、webpack)在依赖图中没有它。 And because of this, bundler doesn't even know about its existence.正因为如此,bundler 甚至不知道它的存在。 So, if I'am correct, such package is not included in bundle.所以,如果我是正确的,那么 package 不包含在捆绑包中。 But, in such case, what's the reason for separating "dependencies" and "dev-dependencies" in package.json, for projects that use any bundler, if bundler decides with its own logic (when it follows "import/export" statements) what to include in output?但是,在这种情况下,对于使用任何捆绑器的项目,如果捆绑器使用自己的逻辑决定(当它遵循“导入/导出”语句时),那么在 package.json 中分离“依赖项”和“开发依赖项”的原因是什么? output 中包含什么?

I think you're right the bundler won't include it when you bundle.我认为您是对的,捆绑程序在您捆绑时不会包含它。 The code is dead-code which should be removed.该代码是应删除的死代码。

But I think (correct me if I'm wrong) that when your consumers of a library do npm install they will have to download everything inside package.json to resolve its dependencies.但是我认为(如果我错了,请纠正我)当您的图书馆消费者执行npm install时,他们将不得不下载package.json中的所有内容以解决其依赖关系。 At least that's my reasoning.至少这是我的推理。

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

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