当前位置: 首页 > article >正文

Vue3.4+element-plus2.5 + Vite 搭建教程整理

一、 Vue3+Vite 项目搭建

说明:

Vue3 最新版本已经基于Vite构建,关于Vite简介:Vite 下一代的前端工具链,前端开发与构建工具-CSDN博客

1.安装 并 创建Vue3 应用

npm create vue@latest

创建过程可以一路 NO

目前推荐使用 Vue Router ---> Yes   ;   ESLint  ---> Yes  ;  Prettier --> Yes

2.启动调试 Vue3 应用

 npm run dev

3.编译发布 Vue3 引用

npm run build

二、Vue3 增加 element-plus UI框架

创建好Vue3 项目后,安装 Element-plus UI 框架

1.安装 element-plus

npm install element-plus --save

2.导入 element-plus,完整导入

// main.js
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'

const app = createApp(App)

app.use(ElementPlus)
app.mount('#app')

3.导入 字体库+导入中文包

import './assets/site.css'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

import { createApp } from 'vue'
import App from './App.vue'
import router from './plugins/index.js'

import * as ElIconModules from '@element-plus/icons-vue'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import VueUeditorWrap from 'vue-ueditor-wrap';


const app = createApp(App)
app.use(router);
app.use(VueUeditorWrap);
app.use(ElementPlus, {
    locale: zhCn,
    // size:'small'
});
Object.keys(ElIconModules).forEach(function (key) {
    app.component(ElIconModules[key].name, ElIconModules[key])
  });
app.mount('#app');

三、Vite 编译配置

vite 官方配置文档:https://vitejs.dev/config/

1.修改启动端口 server.port

  server:{
    port:'8081'
  },

2.修改编译目录 build.outDir

3.修改编译文件路径 build.rollupOptions

  build:{
    outDir: '../QL.Back.Template8/QL.Back.Template8/wwwroot/vue/',//配置输出目录
    input: 'index.html',
    rollupOptions:{
      output:{
        // outDir:'/vue/',
        // 静态资源打包做处理
        chunkFileNames: 'static/js/[name]-[hash].js',
        entryFileNames: 'static/js/[name]-[hash].js',
        assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        }
      }
    }
  },

4.修改引用文件基础路径、引用前缀 base

 base:'/vue/',

完整组合如下:

export default defineConfig({
  base:'/vue/',
  build:{
    outDir: '../QL.Back.Template8/QL.Back.Template8/wwwroot/vue/',//配置输出目录
    input: 'index.html',
    rollupOptions:{
      output:{
        // outDir:'/vue/',
        // 静态资源打包做处理
        chunkFileNames: 'static/js/[name]-[hash].js',
        entryFileNames: 'static/js/[name]-[hash].js',
        assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        }
      }
    }
  },
  plugins: [
    vue(),
  ],
  server:{
    port:'8081'
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

更多:

Vite 下一代的前端工具链,前端开发与构建工具

Vue3富文本组件UEditor ,vue-ueditor-wrap@3.x

基于Vue的移动端UI框架整理


http://www.kler.cn/news/233621.html

相关文章:

  • VUE2和VUE3区别对比一览
  • 【量子通信】量子通信技术:前景与挑战
  • Flask实现异步调用sqlalchemy的模型类
  • Leetcode—135. 分发糖果【中等】
  • C++重新入门-C++数据类型
  • 【深度学习】实验7布置,图像超分辨
  • 论文阅读-Automated Repair of Programs from Large Language Models
  • Python+django企业人力资源公司人事管理系统lq9t2
  • 三、搜索与图论
  • 在 MacOS M系列处理器上使用 Anaconda 开发 Oralce 的Python程序
  • Redis缓存高可用集群
  • Python列表中的insert功能及用法举例
  • 【Flink】FlinkSQL实现数据从Kafka到MySQL
  • 微信小程序,IOS兼容日期格式问题,注意ios高低版本兼容性不一致
  • 【QT+QGIS跨平台编译】之二十八:【Protobuf+Qt跨平台编译】(一套代码、一套框架,跨平台编译)
  • 第62讲商品搜索动态实现以及性能优化
  • python实现基数排序
  • 苹果macbook电脑删除数据恢复该怎么做?Mac电脑误删文件的恢复方法
  • 物资捐赠管理系统
  • 8种基本类型的包装类(与String的转换)
  • 降准是什么意思?降准对股市有哪些影响?
  • 第70讲axios后端请求工具类封装
  • MySQL单主模式部署组复制集群
  • 机器学习聚类算法
  • Collectors.toMap
  • MySQL基础查询篇(9)-数学函数在查询中的应用
  • Linux中的numactl命令指南
  • 代码随想录算法训练营day15||二叉树part02、102.二叉树的层序遍历、 226.翻转二叉树(优先掌握递归)、101. 对称二叉树 (优先掌握递归)
  • MATLAB实现随机森林回归算法
  • 会声会影绿幕抠图操作方法 会声会影绿幕抠图有绿色残边 绿幕抠图视频有绿边怎么处理 抖音怎么剪辑视频 视频剪辑软件推荐