当前位置:网站首页>Vite快速上手
Vite快速上手
2022-06-29 06:32:00 【mun】
认识 Vite
Vite (法语意为 "快速的",发音 /vit/) 是一种新型前端构建工具,能够显著提升前端开发体验。
由两部分组成
一个开发服务器,它基于原生ES模块提供了丰富的内建功能,HMR的速度非常快速; 一套构建指令,它使用rollup打开我们的代码,并且它是预配置的,可以输出生成环境的优化过的静态资源
安装
Vite 需要 Node.js 版本 >= 12.0.0
$ npm install vite
启动项目 npx vite
功能
热模块加载
Vite 提供了一套原生 ESM 的 HMR API,框架利用 API 可以 提供及时、准确更新、无需加载页面或清楚文件状态,
注意哈:这些都是内置在 Vite中,无需配置
对 Css 的支持
Vite可以直接处理 .css 文件 也拥有 HMR
对 css 预处理器
不需要安装特定的插件,但是需要安装相关依赖
# .scss and .sass
npm install -D sass
# .less
npm install -D less
# .styl and .stylus
npm install -D stylus
使用单组件文件需要 <style lang="less"> 会自动开启
Postcss
vite 直接支持 postcss,直接安装postcss并配置 postcss.config.js 文件即可
// 安装 postcss
npm install postcss-preset-env -d
// 配置postcss
module.exports = {
plugins: [
require("postcss-preset-env")
]
}
st
对于.ts也是原生就支持
vue
需要依赖的插件有三个可分别选择
Vue 3 单文件组件支持: @vitejs/plugin-vueVue 3 JSX 支持: @vitejs/plugin-vue-jsxVue 2 支持: underfin/vite-plugin-vue2
安装完之后 对vite.config.js进行配置
import vue from "@vitejs/plugin-vue";
module.exports = {
plugins: [
vue()
]
}
vite 运行打包
通过以下命令进行
npx vite # 本地启动服务
# or
npx vite build # 项目打包
# or
npx vite preview # 本地预览打包内容
可通过配置 pakcage.json进行指令更改
"scripts": {
"serve": "vite", // 本地启动
"build": "vite build", // 项目打包
"preview": "vite preview" // 打包预览
}
view 配置 vue/cli 使用
可通过以下命令
npm init @vite/latest
# or
yarn create vite
稍后如果你没有安装对应的依赖,会提示让你安装对应的依赖,下一步后会要求你选择需要使用的 框架 cli 会有选项供您选择
边栏推荐
- Chapter V online logic analyzer signaltap
- Week 10 - task 0- execution process instance resolution of constructors and destructors
- JDBC | Chapter 5: closing and releasing JDBC connection resources
- Introduction to Ceres Quartet
- Leetcode simple problem building arrays with stack operation
- 目标检测——使用yolov6进行视频推理
- Internet enterprises need CRM software to help
- Ribbon 服务调用与负载均衡
- 配置Flutter开发环境
- How to use regex in file find
猜你喜欢

Easy to understand TCP four waves (multi picture explanation)

Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- path width style function

Rearrangement string of leetcode simple question
![[deep learning] - maze task learning I (to realize the random movement of agents)](/img/c1/95b476ec62436a35d418754e4b11dc.jpg)
[deep learning] - maze task learning I (to realize the random movement of agents)

Single application and microservice application

配置Flutter开发环境

Jenkins operation Chapter 5 trigger, configuration webhook, Jenkins parameterized construction

What is the "danksharding" of V God Kop on Valentine's day?

Why are keys unordered in golang map

Linux Installation redis
随机推荐
力扣每日一题-第30天-1281.整数的各位积和之差
QT writing map comprehensive application 58 compatible with multi browser kernel
Easy to understand TCP four waves (multi picture explanation)
力扣每日一题-第30天-1523.位1的个数
Chapter V online logic analyzer signaltap
After “Go to Definition”, is there a command to return to where you came from?
Subtotal of C language -- basic data types and their representations
百度小程序自动提交搜索
Print Yanghui triangle
'only_ full_ group_ The influence of by'sql mode on group by and its treatment
力扣今日题-324. 摆动排序 II
Monitor employee turnover dynamics. This system makes employees tremble!
Haar cascades and LBP cascades in face detection [closed] - Haar cascades vs. LBP cascades in face detection [closed]
Will the order of where conditions in MySQL affect the union index? Will where 1 =1 affect the use of the index? Does where 1 =1 affect the use of indexes?
Pytest (7) -yield and termination function
Meta metauniverse female safety problems occur frequently. How to solve the relevant problems in the metauniverse?
Week 10 - task 3- from point to circle to cylinder
融入STEAM教育的劳动技能课程
ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience
Object detection - VIDEO reasoning using yolov6