vue设置自定义logo跟标题

准备 Logo 图片 将自定义的 Logo 图片(如 logo.png)放置在项目的 public文件夹下。

使用环境变量设置 Logo 和标题(可选) 创建或修改 .env 文件 在项目根目录下创建或修改 .env 文件,添加以下内容:

javascript 复制代码
VITE_APP_TITLE=JBoltAI 物料小助手
VITE_APP_LOGO=/logo.png

安装 vite-plugin-html 插件:

javascript 复制代码
npm install vite-plugin-html --save-dev  

然后在 vite.config.js 中配置插件:

javascript 复制代码
import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from 'path'
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'
import {createHtmlPlugin} from "vite-plugin-html";

const customerElements = [
    "chat-message",
    'chat-message-panel',
    'chat-opt-panel',
    'chat-tip',
    'msg-tip',
    'reference-item'
]

export default defineConfig(({command, mode}) =>{
    const env = loadEnv(mode, process.cwd(), 'VITE_')
    return {
        plugins: [
            vue({
                template: {
                    compilerOptions: {
                        isCustomElement: tag => customerElements.some(item => item == tag)
                    }
                }
            }),
            createSvgIconsPlugin({
                // 指定需要缓存的图标文件夹
                iconDirs: [resolve(process.cwd(), 'src/assets/svg-icon/local')],
                // 指定symbolId格式
                symbolId: `icon-[name]`,
                // 是否压缩
                svgoOptions: true
            }),
            createHtmlPlugin({
                inject: {
                    data: {
                        ...env
                    },
                },
            }),
        ],
        resolve: {
            alias: {
                '@': resolve(__dirname, 'src'),
                '~': resolve(__dirname)
            },
        },
        server: {
            host: '0.0.0.0',
            port: 3206,
            open: true
        },
    }
})

修改 public/index.html 文件 HTML

html 复制代码
  <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <link rel="icon" href="<%- VITE_APP_LOGO %>">
  <title><%- VITE_APP_TITLE %></title>
</head>
<body>
  <div id="app"></div>
</body>
</html>
相关推荐
EveryPossible21 分钟前
google搜索框
vue.js
海市公约1 小时前
HTML网页开发从入门到精通:从标签到表单的完整指南
前端·ide·vscode·程序人生·架构·前端框架·html
3秒一个大1 小时前
HTML5 与 JavaScript 中的二进制数据处理:ArrayBuffer 与 TextEncoder/Decoder 实践
javascript
purpleseashell_Lili1 小时前
如何学习 AG-UI 和 CopilotKit
javascript·typescript·react
行云流水6261 小时前
前端树形结构实现勾选,半勾选,取消勾选。
前端·算法
diudiu_332 小时前
web漏洞--认证缺陷
java·前端·网络
阿珊和她的猫2 小时前
<video>` 和 `<audio>` 标签的常用属性解析
前端
LSL666_3 小时前
4 jQuery、JavaScript 作用域、闭包与 DOM 事件绑定
前端·javascript·html
yinuo3 小时前
前端跨页面通讯终极指南⑤:window.name 用法全解析
前端
小飞侠在吗3 小时前
vue computed 和 watch
前端·javascript·vue.js