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>
相关推荐
pe7er2 小时前
window管理开发环境篇 - 持续更新
前端·后端
We་ct3 小时前
LeetCode 5. 最长回文子串:DP + 中心扩展
前端·javascript·算法·leetcode·typescript
陈随易7 小时前
有生之年系列,Nodejs进程管理pm2 v7.0发布
前端·后端·程序员
冰暮流星7 小时前
javascript之事件代理/事件委托
前端
@yanyu6668 小时前
登录注册功能-明文
vue.js·springboot
陈随易8 小时前
AI时代,你还在坚持手搓文章吗
前端·后端·程序员
里欧跑得慢10 小时前
17. Flutter Hero动画实现:让界面过渡更加优雅
前端·css·flutter·web
IT_陈寒11 小时前
Vue的这个响应式陷阱,我debug了一整天才爬出来
前端·人工智能·后端
cn_mengbei11 小时前
用React Native开发OpenHarmony应用:Reanimated共享元素过渡
javascript·react native·react.js
kyriewen11 小时前
前端测试:别为了100%覆盖率而写测试,那是自欺欺人
前端·javascript·单元测试