vite + vue 快速构建 html 页面 (舒适编写html文件)

安装

1、安装 node

2、安装 vite、vue、prettier

bash 复制代码
npm i -D vite vue prettier

安装打包插件(可下载源码修改)

bash 复制代码
npm i -D vite-plugin-html-vue-ssr

插件开源地址:https://github.com/Mo-jon/vite-plugin-html-vue-ssr

配置 vite.config.js

javascript 复制代码
import { htmlVueSsr } from "vite-plugin-html-vue-ssr";

export default {
  plugins: [
    htmlVueSsr({
      // 可选的 Vue 组件属性
    }),
  ],
};

html文件编写

html 复制代码
<!doctype html>
<html lang="en">
  <HeadComponent title="index">
    <link rel="stylesheet" href="assets/css/index.css" />
  </HeadComponent>
  <body>
    <HeaderComponent></HeaderComponent>
    <MainComponent>
      <div class="container">
        <div class="flex justify-center">
          <h1 class="font-bold text-3xl title">index</h1>
        </div>
      </div>

      <div class="container">
        <ul class="flex flex-col gap-5 mt-10">
          <li v-for="item in [1,2,3,4,5,6]" class="text-2xl bg-blue-100 p-2">{{item}}</li>
        </ul>
      </div>
    </MainComponent>

    <FooterComponent>
      <script src="assets/js/index.js"></script>
    </FooterComponent>
  </body>
</html>

具体使用可以查看示例项目 https://gitee.com/Mo-jon_admin/vite-vue-html

不想用vite的可以看另外一篇: webpack5 + vue3快速开发html构建静态页面项目(快速开发html模板)https://blog.csdn.net/Mo_jon/article/details/135419866?spm=1011.2415.3001.5331

提示

组件 components 如果想用 .vue 的方式编写可以自己改造实现(解析vue文件到createSSRApp),这里只是简单的实现html的组装(最终是使用createSSRApp实现解析的)

相关推荐
问心无愧05134 小时前
ctf show web入门160 161
前端·笔记
李小白664 小时前
第四天-WEB服务器基本原理,IIS服务
运维·服务器·前端
humcomm5 小时前
AI编程时代新前端职位
前端·ai编程
好家伙VCC5 小时前
Web Components主题热切换方案揭秘
java·前端
甲维斯6 小时前
Kimi版超级玛丽效果“惊人”,配额不足5厘米!
前端·人工智能
hboot6 小时前
AI工程师第一课 - Python
前端·后端·python
凉菜凉凉6 小时前
AI时代,被抛弃的前端
前端·ai
console.log('npc')6 小时前
AI前端工程与生成式UI学习路线
前端·人工智能·ui
梦曦i6 小时前
uni-router v1.1.1发布:守卫超时保护+路由监听
前端·uni-app
qq_2518364577 小时前
基于java Web网络订餐系统设计与实现 源码文档
java·开发语言·前端