博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
node_modules文件夹的大小不是问题。 这是一种特权
阅读量:2516 次
发布时间:2019-05-11

本文共 4585 字,大约阅读时间需要 15 分钟。

I used to get mad at the node_modules folder size. How can a JavaScript application be 100, 200MB in size without even me adding any line of code? I just run npx create-react-app todolist and I downloaded 218,7MB of stuff! (I just checked it now, that’s a real number).

我曾经对node_modules文件夹的大小感到生气。 一个JavaScript应用程序如何在没有我添加任何代码的情况下就可以达到100、200MB的大小? 我只是运行npx create-react-app todolist ,我下载了218.7MB的内容 ! (我现在检查了一下,这是一个实数)。

Whenever you think about the size of node_modules, think about the millions of man hours that we programmers put into it.

每当您考虑node_modules的大小时,请考虑我们程序员投入的数百万个工时。

This is all Open Source software. Software you can inspect and learn from. Kindly donated by programmers and companies all over the world. It’s a global effort that someone made very simple to benefit from. It happened to be npm, the tool first, and the company next.

这是所有开源软件。 您可以检查和学习的软件。 由世界各地的程序员和公司捐赠。 这是一项全球性的努力,有人很容易从中受益。 碰巧是npm ,首先是工具,然后是公司。

We all agreed to publish our code to their servers, and people built things on top, other things on top, until we got to the point that we had quick starters (like create-react-app or the Vue CLI for example) that we can use to get lots of power into our hands for free.

我们所有人都同意将代码发布到他们的服务器上,然后人们在头顶上构建东西,在头顶上构建其他东西,直到我们有了一个快速入门(例如create-react-app或Vue CLI)为止可以用来免费获得大量动力。

Is 200MB too much in the era of TB-order fast storage?

在TB级快速存储时代200MB太多了吗?

Keep in mind that the vast majority of this size is tests, documentation, and what not. And also the vast majority of the code remaining is only used in the development environment. It’s not like you will serve a 200MB application to the client, I think this is well understood.

请记住,这种大小的绝大多数是测试,文档,而并非如此。 而且,剩下的绝大多数代码仅在开发环境中使用。 并不是您会为客户端提供200MB的应用程序,我认为这是众所周知的。

I took the example of create-react-app. What’s in those 200MB?

我以create-react-app为例。 那200MB中有什么?

To start with, create-react-app contains

首先,create-react-app包含

  • a compiler (Babel)

    编译器(Babel)
  • a bundler (Webpack)

    捆绑器(Webpack)
  • a code minifier

    代码压缩器
  • a linter (ESLint)

    短绒(ESLint)
  • a styling pipeline tool (SCSS)

    样式管道工具(SCSS)
  • a development server with live reloading

    具有实时重载的开发服务器
  • a test runner (Jest)

    跑步者(笑话)

If you want to write a Mac or iPhone application, you have to install Xcode, the IDE provided by Apple. Xcode is (wait for it..) almost 14GB in size. That’s 70x the size of node_modules. Granted, we’re comparing two different things, but node_modules contains all you need to start working on your code. You can pair it with VS Code which is 200MB in size, or with Sublime Text which is 30MB - does not matter, no one is even strictly required (while you can’t create an iOS/macOS app without Xcode).

如果要编写Mac或iPhone应用程序,则必须安装Xcode (Apple提供的IDE)。 Xcode大小(等待)大约14GB。 那是node_modules大小的70倍。 当然,我们正在比较两个不同的事物,但是node_modules包含了开始编写代码所需的全部内容。 您可以将它与大小为200MB的VS Code配对,或者与30MB的Sublime Text配对-没关系,甚至没有严格要求的人(尽管没有Xcode不能创建iOS / macOS应用)。

If the concern is your hard disk filling up with modules, is an optimal drop-in solution which centralizes modules in one location and all your apps use those modules instead of making their own local version. It’s used by online coding tools like for example.

如果您担心硬盘中填充了模块,那么是一种最佳的解决方案,它将模块集中在一个位置,并且您所有的应用程序都使用这些模块,而不是制作自己的本地版本。 例如,在线编码工具(例如就使用它。

I’ve read people wonder how they can audit the codebase for security issues or other problems if our apps rely on too much code written by others.

我已经读过很多人想知道,如果我们的应用程序依赖他人编写的过多代码,他们将如何审核代码库中的安全问题或其他问题。

It’s a choice, right? You are not forced to use modules. You can create your own version of tooling that does not require all those modules, but then you’ll have to maintain that code, test it, manage new releases when things need to be updated, and more work.

这是一种选择,对吧? 您没有被迫使用模块。 您可以创建自己的工具版本,该工具版本不需要所有这些模块,但随后您将必须维护该代码,对其进行测试,在需要更新的情况下管理新发行版以及进行更多工作

I’ve had the opportunity to work with other languages and ecosystem where the vibrancy and opportunities of npm would have been a blessing, and instead I had to build my own little library for everything, as the things I found distributed by 3rd part developers were either non-existent or abandoned since a couple years, and not kept up to date with the rest of the language.

我有机会与其他语言和生态系统一起工作,而这对npm的活力和机遇将是一件幸事,而我不得不为所有内容建立自己的小图书馆,因为我发现由第三部分开发人员分发的东西两年以来一直不存在或被放弃,并且未与其他语言保持同步。

Maybe we could have a flag to only download production code rather than all documentation, tests, and what not? But this is just an idea that came to mind now, not sure how this would be doable.

也许我们可以有一个标志来仅下载生产代码,而不下载所有文档,测试,而没有什么呢? 但这只是我现在想到的一个想法,不确定如何实现。

Anyway: long live, node_modules!

无论如何: node_modules

翻译自:

转载地址:http://phqgb.baihongyu.com/

你可能感兴趣的文章
Swift 必备开发库 (高级篇)
查看>>
【转】使用Cocoapods创建私有podspec
查看>>
YTU 2411: 谁去参加竞赛?【简单循环】
查看>>
可能的出栈序列问题
查看>>
vector--C++ STL 学习
查看>>
蜕变成蝶~Linux设备驱动之异步通知和异步I/O
查看>>
代码面试之链表
查看>>
jquery简单开始
查看>>
Android:日常学习笔记(6)——探究活动(4)
查看>>
白话插件框架原理
查看>>
Using Bytecode Outline to View Java bytecode in Eclipse
查看>>
overflow: hidden用法,不仅仅是隐藏溢出
查看>>
javaweb编程思想
查看>>
Linux中cd test和cd /test以及类似命令的区别
查看>>
[BS-26] UIView、pop和Core Animation区别
查看>>
dubbo_rpc原理
查看>>
Java设计模式之《模板模式》及使用场景
查看>>
Linux编程入门
查看>>
坑爹的箭头函数
查看>>
Python 环境搭建
查看>>