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实现解析的)

相关推荐
红尘散仙9 小时前
谁说终端只能敲键盘?我用 Rust 给小说阅读器加上了鼠标
前端·后端·rust
陈随易10 小时前
C++26 草案被否,二十八年来头一回
前端·后端·程序员
ZhengEnCi10 小时前
Agent 工具怎么折叠海量输出才「爽」:Trae、Claude Code 的渐进式披露设计原理
前端·agent
IT_陈寒13 小时前
Redis内存暴涨,没想到是AOF重写捣的鬼
前端·人工智能·后端
ikoala13 小时前
让 Codex 自己查账:一个省 token 的小技巧
前端·后端·ai编程
ikoala13 小时前
AI 写页面像说明书,修 Bug 像贴膏药?把这两句话写进 AGENTS.md
前端·javascript·ai编程
去伪存真16 小时前
AI Agent Harness 深度测评与技术选型实战
前端·agent
FRing0318 小时前
vue2干货总结7(自定义指令、插槽、单页应用程序、路由的使用(VueRouter))
开发语言·前端·vue.js·vue2
疯华整猫21 小时前
被杀掉之后:我把 Android 的「唤起 + 常驻」重做了一遍
前端·面试·架构
ruanno_top1 天前
点全选,已选的被清空了:Transfer 三态复选框的三个 bug
vue.js