简体   繁体   English

devDependencies 会影响包的大小吗?

[英]Do devDependencies affect bundle size?

I looked hard, and couldn't find a straight answer to this question.我仔细看了看,找不到这个问题的直接答案。

Do the packages I add as devDependencies actually end up in the production bundle JS file and thus affect its size?我添加为devDependencies的包实际上最终会出现在生产包 JS 文件中并因此影响其大小吗? Or is it only the dependencies that go into the bundle?或者它只是进入捆绑包的dependencies

No it will not affect your bundle size because those package are only using in development mode.不,它不会影响您的包大小,因为这些包仅在开发模式下使用。 Let's take an example package like typescript让我们举一个像typescript这样的示例包

devDependencies: {
  "typescript": "~3.2.5"
}

So I only need to have typescript compier, linting just in dev mode.所以我只需要打字稿编译器,就在开发模式下进行 linting。 And I not actually import typescript in my project because it's only use for dev mode.而且我实际上并没有在我的项目中导入打字稿,因为它仅用于开发模式。 So if you are using webpack and you are not import typescript anywhere in your project webpack will you tree shaking to eliminate code that are not need for production build so the bundle will not affect.因此,如果您正在使用 webpack 并且您没有在项目 webpack 中的任何位置导入 typescript,您是否会通过摇树来消除生产构建不需要的代码,这样 bundle 就不会受到影响。

The answer is not that easy as might look.答案并不像看起来那么容易。 Here is clarification: https://github.com/webpack/webpack/issues/520#issuecomment-174011824这里是澄清: https : //github.com/webpack/webpack/issues/520#issuecomment-174011824

And adding relevant snippet here:并在此处添加相关片段:

A browser app built by webpack has no runtime node dependencies, and thus all frontend dependencies should be listed as devDependencies. webpack 构建的浏览器应用程序没有运行时节点依赖项,因此所有前端依赖项都应列为 devDependencies。 The dependencies vs devDependencies naming convention stems historically from node being a server side package manager, which was abused into a frontend package manager, and this is why the fields have names that are counter-intutive when applied to frontend dev, and is why every project ever is getting this wrong.依赖与 devDependencies 命名约定历史上源于 node 作为服务器端包管理器,它被滥用到前端包管理器中,这就是为什么这些字段在应用于前端开发时具有违反直觉的名称,这也是每个项目的原因曾经犯过这个错误。 It is as far as I can tell harmless to list frontend dependencies under dependencies, but it is wrong.据我所知,在依赖项下列出前端依赖项是无害的,但这是错误的。

I hope this answers your question.我希望这回答了你的问题。

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

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