Vite tutorial, extremely fast build tool, getting started,

Getting started with Vite

Vite is an extremely fast build tool that replaces webpack



Preface

Before browsers supported ES modules, developers did not develop native JavaScript mechanisms in a modular way. This is also the reason for the emergence of the concept of "packaging". The packaging here refers to construction tools such
as webpack . However, as the projects packaged by webpack become larger and larger, the time required for each packaging becomes longer and longer, even if there are In the hot update method, webpack generally takes about 1 second, and you have to wait for a CSS adjustment.
But as the browser starts to support ES modules natively, using the browser’s native support to package will reduce the time to the millisecond level.


Tip: The following is the content of this article, the following cases are for reference

1. What is Vite?

Vite (French means "fast", pronounced /vit/) is a new front-end construction tool that can significantly improve the front-end development experience. It is mainly composed of two parts:
a development server, which provides rich built-in functions based on native ES modules, such as the amazingly fast module hot update (HMR).
A set of build instructions, it uses Rollup to package your code, and it is pre-configured to output optimized static resources for production environments.
Vite intends to provide out-of-the-box configuration, and its plug-in API and JavaScript API bring high scalability and complete type support.

Second, use steps

1. Use npm

code show as below:

npm init @vitejs/app

Insert picture description here
Enter project name

Insert picture description here
Then you can select the preset template. Here, the vue Insert picture description here
project has been created, and then cd to the project folder to install

2. Installation dependencies

code show as below:

npm install 

It is recommended to use cnpm in China

cnpm install 

3. Run the test server

Run directly with npm run dev

npm run dev 

Insert picture description here

You can see that the test server is already running on port 3000


4. Fast! Fast! Fast! Fast! Fast!

The following is a comparison with webpack. The first one uses vite. After pressing ctrl+S, the page changes almost at the same time.

Insert picture description here

On the webpack side, it takes about half a second to build, and the build process will also be displayed in the console.

Insert picture description here

to sum up

The construction time gap in the initial template project alone is so large. It can be imagined that Vite can improve the development efficiency of large projects. Vite can be said to be an alternative to webpack.

Guess you like

Origin blog.csdn.net/qq_41636947/article/details/114992350