当前位置:网站首页>Vite learning (I) - Introduction
Vite learning (I) - Introduction
2022-06-23 06:03:00 【Uncertainty】
brief introduction
vite Is a browser based native ES-Module Front end building tools for . The official website describes The next generation of front end development and construction tools .
The next generation ?
There is the concept of the next generation , Let's first understand what the previous generation tools are .
es6Our code specifications were all community specifications before they appeared , for examplenodeThe use ofcommonjsstandard , And the service clientAMD、CMDstandard .es6When it appears , Code modularization has language specification , namelyES-Modulestandard So now that there are official standards , We can consider abandoning community norms , Uniform use of official guidelines .
characteristic
- Quick cold start ( Used
esbuildcompile ) - Instant module hot update
- True on demand compilation ( Leverage native capabilities , Cannot package and rebuild )
- Low community cost ( compatible
rollupplug-in unit )
principle : utilize
ES6OfimportWill send a request to load the file feature , The server intercepts these requests , Do some precompiling ( Browser does not recognize.vueDocuments, etc. ), Omit webpack Long packing time .
Esbuild
similar webpack Front end building tools for , But use go language-written , Multithreaded parallel execution
Tool comparison
Front end construction tools commonly used at present webpack, The common scaffolds we use are also based on it . Next, make a general comparison between the two tools :
webpack vs vite
webpackIt can be developed 、 structure 、 pack ;viteJust for development 、 structure 、 Stage , Packaging depends onrollupTools .viteprinciple- Statement
scriptThe label type should bemodule - The browser launches a
getRequest to find the file - If there is still
importMy bag , Will continue to make requests viteIts function is to intercept the requests initiated by the browser , Process files on the server side , Back to the browser , The whole process is not packaged and compiled , So it's much faster
- Statement
viteThe parsing implementation process is as follows :- The development server uses
http+connectBuild a service - Processing request resources through a variety of middleware ; It's going to traverse
htmlnode , ElementalsrcAttribute addedbasePrefix , Convert inline scripts to network requests - Will pass
es-module-lexerThis library analyzes allimportsentence viteWill be added after the requestqueryMethod of parameters , The processing logic used to identify the current request
- The development server uses
webpackPackaging process- Identify the entry file
- Identify by layer by layer module dependencies ( Yes
require、importAnalyze to obtain dependencies ) - Use for different file types
loaderHandle - transformation 、 compile 、 Output the final code
webpackPacking principle- Step by step recursively identify dependencies , Building a dependency map
- Turn the code into
ASTGrammar tree - stay
ASTStage processing code - hold
ASTThe constructed syntax tree is transformed into code recognized by the browser , Output the last output file ,webpackDid it on its ownrequirefunction , File dependent import ; Use of loaded filesjsonpHow to achieve
webpack Disadvantages and vite improvement
webpackCold start slow , Because you need to compile all the files ;viteUse browser nativeESMAbility , Only files used on the current screen will be processed , Don't compile them all .
webpackUse innodejsWritten packer builds ;viteUseesbuild(go)Build dependencies , ThanjavascriptThe tools written are fastwebpackAfter editing the file, the file will be hot replaced again ( modular ) In itself , The thermal renewal efficiency slows down as the project volume increases ;vitein ,HMRIt's in the originalESMPerformed on , Regardless of the application volume , Can update the module itself more accurately . At the same time, strong cache and negotiation cache are used to avoid unnecessary requests .webpackHas been updated to the fifth generation ,loaderandpluginEnrich , Ecology is better thanvite. howeverviteThe momentum is booming , I believe that community development is only a matter of timeviteThe packaging of is still dependent onrollupvitein the light ofvue,react,svelteBasic templates are provided
Easy to use
- adopt
viteCreate project npm init @vitejs/app( You may be prompted to install globally@vitejs/create-app)
vanilla Templateless native mode
> vue vue3
react
preact
lit
svelteYou can install it according to your choice
- Project structure
moduleForm introductionjsfile
vite.config.js The configuration file ,vue The default is setup Development mode , If you want to use jsx Development , The plug-in needs to be installed separately
npm run dev
- Want to use
jsxDevelopment import { defineComponent } from "vue"; export default defineComponent({ setup() { return () => { return <h3> I am a jsx</h3> } } }) modifymain.jsimport { createApp } from 'vue' import App from './App' ////////// createApp(App).mount('#app') npm i @vitejs/plugin-vue-jsx -D- newly build
App.jsxfile
establish vue2 project
We use it vite Know when you create a project , No, vue2 Options for templates , That's for familiarity vue2 What should students of the technology stack do ?
We recreate the project selection vanilla Templates , The simplest form .
- establish
vite.config.jsimport { createVuePlugin } from 'vite-plugin-vue2' export default { plugins: [createVuePlugin()] } - install
vue2、npm i vue -S - The directory structure is as follows
- Write test code edit
main.jsfile import Vue from 'vue' import App from './App.vue' new Vue({ el: '#app', render: h => h(App) }).$mount() editApp.vuefile <template> <div> vue2 </div> </template>
Use the community vue2 Templates
open awesome-vite
The downside is that you need clone Its project , Development .
vite That's all for the introduction, simplicity and practicality of , Learn the next chapter vite Use static resources in , Using environment variables .
边栏推荐
- 编址和编址单位
- PAT 乙等 1016 C语言
- mongodb项目中可能出现的坑
- jvm-02.有序性保证
- True MySQL interview question (24) -- row column exchange
- Android handler memory leak kotlin memory leak handling
- PAT 乙等 1020.月饼
- [OWT] OWT client native P2P E2E test vs2017 build 6: modify script automatic generation vs Project
- Wechat tried out the 1065 working system, and was forced to leave work at 18:00; It is said that Apple will no longer develop off screen fingerprint identification; Amd chief independent GPU architect
- Pyqt5 设置窗口左上角图标
猜你喜欢

Ant Usage Summary (II): description of related commands

New classes are launched | 5 minutes each time, you can easily play with Alibaba cloud container service!

Addressing and addressing units

Visual studio debugging tips
![[OWT] OWT client native P2P E2E test vs2017 build 6: modify script automatic generation vs Project](/img/ce/2e0b0c0f6fae24b5b0df2680229284.png)
[OWT] OWT client native P2P E2E test vs2017 build 6: modify script automatic generation vs Project

Deploy docker and install MySQL in centos7

十一、纺织面料下架功能的实现

mongodb 4.x绑定多个ip启动报错
![[cocos2d-x] erasable layer:erasablelayer](/img/6e/1ee750854dfbe6a0260ca12a4a5680.png)
[cocos2d-x] erasable layer:erasablelayer

Memory analysis and memory leak detection
随机推荐
jvm-01.指令重排
Android handler memory leak kotlin memory leak handling
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.3 全双工, 节能, 自动协商机制, 802.1X 流控制 / 3.3.3 链路层流量控制
jvm-03.jvm内存模型
Pat class B 1014 C language
Pat class B 1019 C language
Huawei's software and hardware ecosystem has taken shape, fundamentally changing the leading position of the United States in the software and hardware system
The official artifact of station B has cracked itself!
PAT 乙等 1018 C语言
[open source project] excel export Lua configuration table tool
Pat class B 1018 C language
Centos7 installation of postgresql8.2.15 and creation of stored procedures
Pat class B 1021 digit statistics
Real MySQL interview questions (XXVI) -- didi 2020 written examination questions
Work accumulation - judge whether GPS is on
PAT 乙等 1015 C语言
Excel sheet column number for leetcode topic resolution
About the error of installing PIP3 install chatterbot
Leetcode topic analysis add binary
Wechat tried out the 1065 working system, and was forced to leave work at 18:00; It is said that Apple will no longer develop off screen fingerprint identification; Amd chief independent GPU architect