#uniapp添加自定義index.html#

一:自定義模板用途

通常有以下幾種情況


調整界面 head 中的 meta 配置
補充 SEO 相關的一些配置「僅首頁」
加入百度統計等第三方js
自定義模板添加 favicon 的了。


二:實現步驟
1、工程跟項目新建一個 XXX.html 文件,文件名字自己定義,比如 template.html
2、複製基本模板內容到這個html文件,在此基礎上修改meta和引入js;

<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <title>
            <%= htmlWebpackPlugin.options.title %>
        </title>
        <link rel="icon" type="image/png" sizes="32x32" href="static/favicon.png"/>
        <script>
            document.addEventListener('DOMContentLoaded', function() {
                document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
            })
        </script>
        <link rel="stylesheet" href="<%= BASE_URL %>static/index.<%= VUE_APP_INDEX_CSS_HASH %>.css" />
    </head>
    <body>
        <noscript>
            <strong>Please enable JavaScript to continue.</strong>
        </noscript>
        <div id="app"></div>
        <!-- built files will be auto injected -->
    </body>
</html>

3:添加自定配置項
例如:
這 head 中加入我們的 favicon 文件
<link rel="icon" type="image/png" sizes="32x32" href="http://img.sscai.club/favicon1.png"/>


4:在 manifest.json -> h5 -> template 節點中關聯這個html文件的路徑。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章