vite基本配置
文章目录
相关文档
提示:
- 安装包可通过
npm或yarn方式安装 - 我目前安装的
vite版本是^2.1.5, 配置仅供参考
scss预处理器
- 无需下载
node-sass、 sass-loader包, 直接安装sass - 同样的
less、 stylus也是直接安装
// .scss and .sass
npm i sass -D
// .less
npm i less -D
// .styl and .stylus
npm i stylus -D
- 引入全局
scss样式, 在vite.config.js中配置
preprocessorOptions: {
scss: {
additionalData: "@import './src/assets/style/mixin.scss';"
}
}
- 使用
<style lang="scss" scoped>
img {
width: $width;
}
#wrap {
width: calc(100% - #{$width});
}
</style>
样式自动添加前缀
- 安装
npm install autoprefixer postcss -D
- 可以在
vite.config.js文件中配置 或 新建postcss.config.js配置文件, 配置如下
// vite.config.js 配置
css: {
postcss: {
plugins: [
require('autoprefixer')
]
}
},
// postcss.config.js
module.exports = {
plugins: [
require('autoprefixer')
]
}
vue-router
- 安装 vue-router
npm install vue-router@4 -S
- 在
App.vue中 将组件映射到路由上
<template>
<router-view></router-view>
</template>
- 定义路由组件, 新建
router文件夹下为index.js
import {
createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
// 定义路由
const routes = [
{
path: '/',
redirect: '/index'
},
{
path: '/index',
name: 'index',
component:

本文详细介绍了如何配置Vite环境,包括SCSS预处理器的使用、样式前缀自动添加、Vue Router路由管理、axios和Vuex状态管理,以及Element Plus组件库的引入和alias别名设置。
最低0.47元/天 解锁文章
9398

被折叠的 条评论
为什么被折叠?



