🚀 Farm V1.0 is released! #1194
wre232114
announced in
Announcements
Replies: 1 comment
-
Amazing job!🤩 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Farm⭐️ is a next-generation web build tool written in Rust. It is currently the most powerful, fastest, and most stable Rust web build tool. Since Farm open its source code of version 0.3 in March 2023, after a year of development and contributions by many community developers, version v1.0 has finally been released! The v1.0 version supports a large number of features including
lazy compilation
,persistent caching
,Rust/Js plugins
,partial bundling
and other capabilities. It is also compatible with the Vite plugin ecosystem. On the basis of perfectly solving the drawbacks of existing tools such as Vite, Farm has both extreme performance and compatibility, it is the real next generation web build tool!As shown below, in benchmark test of 1000 react components, Farm is 20 times faster than webpack and 10 times faster than Vite. Compared with other tools, it has overwhelming performance advantages in terms of cold start, hot start, HMR, etc. Farm supports and enables a series of performance optimization methods by default, such as
lazy compilation
,persistent cache/incremental build
,multi-threaded parallel compilation, etc.
. The larger the project, the more the source files, and the greater the performance advantage.1. Features
Html
,Css/Css modules
,js/jsx/ts/tsx
,static resources
and so on.bundle
andbundless
and can ensure loading performance while improving cache reuse rate.Farm v1.0 supports common frameworks such as React, Vue, Solid, Svelte, etc. The project examples section below introduces the use of Farm to build real projects and shows the performance benefits after migration:
2. Quick Start
Farm provides official templates to quickly create a React, Vue, Solid, Svelte, etc. project:
Then select the type of project, features, etc. to be created. After the project is created, start the project:
As shown in the picture below, you can create and start your first Farm project in 20 seconds!
For more details, please refer to Official Document
3. Compilation features
3.1 Basic compilation capabilities
Farm has built-in compilation capabilities for common modules such as
TS/TSX/JS/JSX
,CSS/CSS Modules
,HTML
,static resources
, etc., and can be used out of the box without any configuration. For a web app project, you can directly usehtml
as the entry point and importJS/TS
andcss
files. A simplest React project example is as follows, except that@farmfe/plugin-react
needs to be installed to support React In addition to Jsx syntax transformation and react refresh injection, other capabilities can be used out of the box../src/index.tsx
is imported in the above html:Import the css file through
import './index.css';
:Out-of-the-box compilation support is provided for
css modules
and static resources such aspng/svg/font
:These basic compilation capabilities are implemented in pure Rust, no additional plugins are needed. For files of
html
,ts/tsx
,css/css modules
,png/svg/font and other static resources
, they can be compiled and bundled out of the box. Farm treats various types of moduleshtml
,css
,js/ts/tsx
, etc. as first-class citizens, and bundle various types of modules into several deployable products, using the same bundling rules.3.2 Lazy compilation
For any dynamically imported modules (including
js/ts
,css
, etc.), compilation will be delayed and will only be compiled when the resources actually need to be loaded. This will greatly improve the startup performance of large projects! For example, for large projects, there are often multiple dynamically loaded routes:When
lazy compilation
is enabled,import('./pages/home.vue')
will only be compiled when the/home
route is accessed. Other routes such as/about
will also not be compiled before being accessed. Neither/pages/about.vue
nor its dependencies will be compiled. Through reasonable use oflazy compilation
+persistent cache
, the startup time of each route in large projects can be compressed to less than1s
, greatly improving the development performance of large project!Lazy Compilation
can be configured throughcompilation.lazyCompilation
and it is enabled for start by default.3.3 Incremental Building
Farm supports caching module level compiled products to the local disk to support
incremental building
. Any module won't be compiled twice before it is changed! Incremental building can reduce project startup time by about 80%. For React + Arco Pro Admin Projects, the performance comparison between code start and hot start is as follows:| |Cold start (without cache) | Hot start (with cache) | Performance gap |
| -------------------- | --------------- | ----- | ------ ----- |
| start | 1519ms | 371ms | Hot start reduction 75% |
| build | 3582ms | 562ms | Hot build reduction 84%
Incremental Building
can be configured throughcompiltion.persistentCache
and it is enabled by default.When incremental building is enabled, Farm will cache all compilation actions that affect performance to
node_modules/.farm
directory at module granularity, for example,resolve/load/transform/parse AST
,compression
,code generation
and so on, during the next compilation, the cache will be read from the.farm
directory, eliminating a large number of repeated calculations to greatly improve the compilation performance.For more details, refer to the document Incremental Build
3.4 Production Optimization/Browser Compatibility
Farm fully supports production builds. Many enterprise projects have already used or migrated to Farm, and the results are quite good!
For production builds, Farm has the following optimizations enabled by default:
export
and other statements will be deleted to reduce the product sizeES2017
specification, and automatically downgrade syntax that is not supported by ES2017, and automatically inject Polyfill for unsupported APIs.Farm supports downgrading products to
ES5
. If your project has strong compatibility requirements, you can configure it throughtargetEnv: 'browser-legacy'
:For more details, please refer to the document Build For Production
3.5 Partial Bundling
Currently, there are two main ways for build tools (such as
webpack
,rollup
) to handle modules:Full bundling
ornative ESM
. But they all have disadvantages:full bundling
, the bundler is designed to bundle everything together and then split it out for optimization, but code splitting is often difficult to configure and manually balancing resource loading performance and cache hit rate is difficult.native ESM
, each module can be compiled and cached separately, but when the project scale becomes large and there are hundreds or thousands of module requests, the loading performance will be seriously affected.So I've been wondering if there is a strategy to avoid these two extreme cases - maybe we could do
partial bundling
? We can directly bundle the project into a number oflimited quantity
andbalanced size
resources. I named this kind of thinkingPartial Bundling
- Find a balance betweenFull Bundling
andNo Bundling
, by partial bundling related modules to improve loading performance, while not losing cache granularity as much as possible.Based on the idea of Partial bundling, Farm designed a complete set of bundling algorithms and provided an full implementation. Unlike other build tools, Farm does not try to bundle everything together and then split the bundle using optimization strategies like
splitChunks
. Instead, Farm bundles the project directly into multiple product files. For example, if hundreds of modules are needed to launch and render anhtml
page, Farm will try to bundle them directly into 20 to 30 output files based on thepartial bundling
algorithm.The goals of
Farm Partial Bundling
are:For traditional bundler, it may be difficult for us to achieve the above goals through complex
splitChunks
ormanualChunks
configuration, but Farm supports it natively throughpartial bundling
.For more details on partial bundling, refer to the document Partial Bundling.
3.6 Plugin Ecosystem
Farm is completely pluggable, and has designed a complete plugin system for community plugins. Currently Farm supports the following 4 types of plugins:
Farm compilation plugin
: Supports Rust plugin and Js plugin, using rollup style hooksFarm Rust Plugin
: Plugin written in Rust, which has the best performanceFarm Js plugin
: Plugin written in JS, the performance is worse than Rust, but it is more convenient to writeFarm runtime plugin
: Extend Farm’s runtime module systemVite/Rollup/Unplugin
: Farm supports theVite/Rollup/Unplugin
plugin out of the boxSwc
plugin**: Farm supports the
Swc` plugins out of the boxAn overview of Farm plugin hooks is as follows:
Farm provides a large number of official plugins to support common compilation capabilities, such as:
@farmfe/plugin-react
: supports React Jsx conversion and React Refresh@farmfe/js-plugin-sass
: supports Sass compilation@farmfe/js-plugin-less
: supports Less compilation@farmfe/js-plugin-postcss
: supports Postcss compilation*...
Most of the
Vite/Rollup/Unplugin
plugins are available out of the box in Farm:@vitejs/plugin-vue
: supports Vue compilation@vitejs/plugin-vue-jsx
: supports Vue Jsx compilationunplugin-auto-import
unplugin-auto-component
*...
For information on using various plugins in Farm, please refer to Using Plugins. For an introduction to official/community plugins, please refer to [Plugins](https://www. farmfe.org/docs/plugins/official-plugins/overview)
Writing your own Farm plugin is also quite simple. Farm provides plugin templates for one-click creation:
Supports both
Rust
plugins andJS
plugins, please refer to the document Writing Plugins for details.3.7 SSR support
Farm supports SSR (Server-Side Rendering). SSR can greatly improve the loading performance of the first screen, improve the SEO of the page, etc. Based on Farm, you can achieve extremely fast SSR building experience!
A typical Farm SSR project structure is as follows:
You need to provide the
client
andserver
entries respectively, and then use Farm to build theclient
andserver
entries. Farm provides SSR examples for common frameworks:For more details about SSR, refer to the document Server-Side Rendering
4. Real Project Examples
Farm supports common frameworks such as React, Vue, Solid, Svelte, etc., and real projects have been migrated from Webpack/Vite to Farm. Below we provide examples of admin projects for the two most commonly used frameworks (React, Vue).
4.1 React Admin Project
React
+Arco Pro
+Farm
As shown in the picture above, Farm can hot-start and render a complex admin project in 500ms.
4.2 Vue project
Vue
+Element Plus
+Farm
In the picture below(Farm is at the bottom and Vite is at the top). It can be clearly seen that under the same conditions of compiling the Vue project with
hot start
+full Vite plugin
, Farm is5
times faster than Vite. This project is migrated from Vite to Farm. Since Farm is compatible with the Vite ecosystem, all Vite plugins of the project can be directly reused, the migration is really simple.5. Summary
Farm is developed and built by the open source community. After nearly two years of development, version 1.0 has finally been released. Version 1.0 includes all the capabilities needed for web build tools. Through
Rust multi-threading
+lazy compilation
+incremental compilation
, etc., it greatly improves web project build performance and provides a more extreme building performance experience!In the future Farm will:
Acknowledgments:
This discussion was created from the release 🚀 Farm V1.0 is released!.
Beta Was this translation helpful? Give feedback.
All reactions