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

相关推荐
MrDJun14 分钟前
分享一款免费实用的网页变动监控工具:PageWatch.tech
前端·javascript·vue.js
米码收割机15 分钟前
【web】邻里悦站—社区便民服务平【独一无二】(源码+说明文档)
前端
程序员爱钓鱼24 分钟前
Rust Option 详解:安全处理“可能存在,也可能不存在”的值
前端·后端·rust
程序员爱钓鱼25 分钟前
Go Modules 包管理详解:go.mod、go.sum 与依赖管理
前端·后端·go
qq_589666059 小时前
TypeScript 完整入门教程
前端·javascript·typescript
用户0595401744612 小时前
LLM对话记忆测试踩坑实录:手工回归30分钟,自动化后2分钟发现3个隐藏Bug
前端·css
Ashley的成长之路13 小时前
前端性能优化实战手册·第2篇:资源加载策略全解
前端·性能优化·资源加载·http/3·性能优化实战·资源加载优化
浅水壁虎13 小时前
vue基础(第二章 )
前端·javascript·vue.js
界面开发小八哥13 小时前
界面控件DevExtreme v26.1新版亮点——支持Angular 22
前端·javascript·angular.js·devexpress·ui开发·devextreme