[vite]Why is vite faster than webpack?

Why is vite faster than webpack? Let's give an example

The reason for this problem is caused by the construction mechanism of webpack.

When webpack is developed and built, it will build all your pages by default, crawl the entire application and provide services later. This will cause an error anywhere in your project (even though you have not yet entered this page). This all affects build speed, so the larger your project, the longer webpack will take to build and the slower it will start.

For Vite, the same error will only appear when he enters this page, because Vite will not build your project at the beginning, but will divide the application into [Dependencies] and [ Source code], he will split the source code part according to [routing], and only build the content that must be built from the beginning. At the same time, Vite provides the source code to the browser in the form of [native ESM], allowing the browser to bear part of the packaging It is precisely because of this mechanism that no matter how big your project is, it will build what must be built at the beginning, thus greatly improving the speed of construction.

【Replenish】

Some people may wonder if using the native esm method means that it cannot be built if we use commonjs or other methods?

The official website gives the answer, Vite will solve this problem by relying on pre-built

 

Guess you like

Origin blog.csdn.net/wuguidian1114/article/details/126020526