Kros的博客 Kros的博客
首页
  • CSS
  • 工具
  • Vue
  • js
  • Vue3
  • 算法
  • 折腾笔记
一言
  • 分类
  • 标签
  • 归档
码云

Kros

凡心所向,素履以往,生如逆旅,一苇以航
首页
  • CSS
  • 工具
  • Vue
  • js
  • Vue3
  • 算法
  • 折腾笔记
一言
  • 分类
  • 标签
  • 归档
码云
  • CSS

  • JavaScript

  • 工具

    • git命令行
    • uniapp小程序分包配置
    • VScode使用Todo tree实现待办查看
    • activiti editor添加自定义属性
    • uniapp使用svg
    • windows端口查看及关闭端口
    • uniapp通过wifi无线运行到手机
    • android生成证书文件
    • vscode中显示换行指示线
    • 浏览器console输出自定义样式内容
    • console的非常规用法
    • uniapp App升级更新
    • 从零开始搭建脚手架1
    • vite打包插件上传到npm
    • uniapp使用speech模块遇到的问题
    • HbuilderX使用MuMu模拟器
    • HbuilderX调试app页面元素
    • 前端工程化的理解
    • console log打印obj非实时性数据问题
    • 常见http状态码
    • HbuilderX配置自定义打包环境
    • webpack优缺点
    • axios和ajax的区别
    • 使用docxtemplater导出word文件
    • docxtemplater循环列表数据导出
    • js打开钉钉打卡页面
    • uniapp配置自定义环境变量和条件编译变量
    • 文件上传时的各种二进制数据关系
    • 解决开发过程中的跨域问题
    • vue自定义入口html文件
    • tsParticles局部粒子效果
    • 使用verdaccio搭建私人npm仓库
  • Vue

  • antdv踩坑记录

  • Vue3

  • 前端
  • 工具
kros
2025-08-07

vue自定义入口html文件

# vue2

在vue.config.js中添加如下配置

module.exports = {
  pages: {
    index: {
      // 修改入口文件
      entry: 'src/main.js', // 入口文件路径
      template: 'public/custom.html', // 模板文件路径
      filename: 'index.html', // 输出文件名
    }
  }
}
1
2
3
4
5
6
7
8
9
10

# vue3

在vite.config.js中添加rollupOptions配置

// 自定义插件
const renameHtmlPlugin = () => {
  return {
    name: 'index.html',
    enforce: 'post',
    generateBundle(_, bundle) {
      if (bundle['custom.html']) {
        bundle['custom.html'].fileName = 'index.html';
      }
    },
  };
};
export default defineConfig(({ mode }) => {
  // 加载环境变量
  const env = loadEnv(mode, process.cwd())
	const isCustom = env.VITE_APP_CUSTOM 
  return {
    build: {
      outDir: 'dist', // 打包输出目录
      // 配置入口html
      rollupOptions: {
        input: isCustom ? '/custom.html' : '/index.html',
      },
    },
		plugins: [
			renameHtmlPlugin()
		]
	}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

修改入口html后打包产物也是按custom命名的,这里我们需要把入口再重命名为index.html,如上,我们在plugins中添加自定义插件即可。

上次更新: 2025/09/05, 8:09:00
解决开发过程中的跨域问题
tsParticles局部粒子效果

← 解决开发过程中的跨域问题 tsParticles局部粒子效果→

最近更新
01
Find the next perfect square
09-05
02
Regex validate PIN code
09-05
03
Find the odd int
09-05
更多文章>
Theme by Vdoing | Copyright © 2020-2025 kros king
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
icon-heart-o icon-heart icon-infinity icon-pause icon-play link next prev