简体   繁体   中英

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. Will this package be included in final build (ex. rollup output)?

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. And because of this, bundler doesn't even know about its existence. So, if I'am correct, such package is not included in bundle. 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?

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. At least that's my reasoning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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