MOXUY

Mar 13, 2023

英语学习之文档翻译(1)

https://farm-fe.github.io/docs/why-farm/

Why Farm?

Me: 为什么使用Farm?

ChatGpt: 为什么需要 Farm?

As the web project scales, building performance has been the major bottleneck, for a huge project, compiling with webpack may cost 10min or more, a hmr update may cost 10s or more, heavily reduced the efficiency.

Me: 作为web项目扩展,为大型项目构建高性能的主要障碍,使用webpack编译可能需要10分钟或以上的时间,一次HMR更新可能要花10秒或以上的时间,大大的降低了效率。

ChatGPT: 随着 Web 项目规模的扩大,构建性能成为了主要的瓶颈。对于一个庞大的项目,使用 webpack 进行编译可能需要花费 10 分钟甚至更长时间,HMR 更新可能需要 10 秒或更长时间,严重降低了效率。

Then some tools like vite comes out, it uses native ESM and is unbundled for source files in dev mode, pre-bundle dependencies using esbuild, which makes the dev server launch and the HMR very fast.

Me: 一些像Vite这样的工具发布,它在开发模式中使用了原生ESM和源文件unbundled,使用esbuild的预打包依赖关系,使运行开发服务和HMR非常快。

ChatGPT: 随后,一些像 Vite 这样的工具应运而生。它使用原生 ESM,并在开发模式下为源文件进行解包,使用 esbuild 预打包依赖项,使开发服务器启动和 HMR 很快。

But Unbundled is not perfect, there are still big problem when comes for a large project:

Me: 但是Unbundled不是完美的,当开始一个大项目时,那仍然是一个大问题:

ChatGPT: 但解包并不完美,对于大型项目仍然存在一些问题:

  • The huge numbers of module requests: For a large project, there may be thousands of modules that should be loaded, using native module system to load thousands of modules will make the browser get stuck or even crashed

  • Me: 巨大的模块请求数:对于一个大型项目,可能需要加载数千个模块,使用系统原生模块去加载数千个模块时,将导致浏览器卡住或甚至崩溃。

  • ChatGPT: 模块请求数量巨大:对于大型项目,可能要加载数千个模块,使用原生模块系统加载数千个模块将使浏览器卡顿甚至崩溃。

  • Inconsistency between Dev and Production: Native module can not be used in production for most situations, For the compatibility and request numbers. So Unbundled tools choose to bundle in production. This brings inconsistency, when there are production bugs caused by this inconsistency, it’s really hard to debug and really painful. And vite is using esbuild in dev and using rollup in production, which enlarged the inconsistency.

  • Me: 开发和生产不一致:原生模块更多情况下不能被用于生产,对于兼容性和请求数来说。所以Unbundled工具选择在生产环境中使用bundle。这带来不一致性,当这些不一致造成了生产问题时,真的很难去解决,并且这也很痛苦。Vite在开发环境使用esbuild,生产环境使用rollup,这扩大了不一致性。

  • ChatGPT: 开发和生产之间的不一致性:原生模块在大多数情况下不能用于生产,因为其兼容性和请求量。因此,解包工具选择在生产中进行打包。这带来了不一致性。当这种不一致性导致生产问题时,很难进行调试,也很痛苦。而 Vite 在开发中使用 esbuild,在生产中使用 rollup,这加大了不一致性的程度。

And Vite is so fast in dev because of esbuild, which is written in go. Go takes advantages of native platform and much faster than Js.

Me: Vite因为使用了esbuild,所以在开发环境十分的快,esbuild用go所编写。Go利用原生平台比Js更快。

ChatGPT: 而 Vite 之所以在开发中如此快速,是因为 esbuild 写成了 Go 语言。Go 优于 JavaScript,它利用原生平台,并且更快。

So I thing we just need a fast, powerful, consistent web bundler, which can solve the problems above and fast, then I designed Farm.

Me: 所以,我认为我们需要一个快的,强大的,一致的web打包工具,这将解决上面的问题并且还很快,因此我设计了Farm。

ChatGPT: 因此,我认为我们需要一个快速、强大、一致的 Web 打包工具,可以解决以上问题,并且速度快,于是我设计了 Farm。

And Farm is not just a normal bundler re-written in Rust, it has a lot of powerful and progressive designs:

Me: Farm不是简单的使用result重写的打包工具,它有很多强力和先进的设计:

ChatGPT: Farm 不仅是 Rust 语言的一个普通打包工具,还有许多强大的和先进的设计:

Farm Design Philosophy
Performance first: Everything will be written in Rust as long as we can, only several parts which is not the performance bottleneck will be written in JS
Consistence first: Make sure that the development and production exactly the same by default, what you see in development will be the same as what you got in production.
Partial Bundling: The bundling goal of Farm is not to bundle everything together, but to limit the request numbers of resources. Farm will bundle your project into 20-30 small resources according to the dependency relation and resource size, to get the best resources loading performance without losing caching granularity.
First class citizen support of all web assets: Farm won’t need to transform everything to Javascript any more, it treats anything as first class citizen, assets like html, js/jsx/ts/tsx, css/scss, png/svg/… are all basic modules supported by Farm, more assets can be supported by plugins.
Compatibility: Farm will work with both legacy(ES5) and modern browser.
Rollup style plugin system: Easy to create your own plugins and easy to migrate your plugins/projects from rollup/vite/webpack.
Farm’s goal is to be the real next generation build tool, fast, powerful, consistent, and providing best development experience for web developers

tags: 英语 翻译
OLDER > < NEWER