Web:Client: add favicon hash with HtmlWebpackPlugin

This commit is contained in:
Timofey Boyko 2023-01-23 16:13:51 +03:00
parent 34a6b8eefa
commit fd5423e04c
3 changed files with 86 additions and 29 deletions

View File

@ -11,14 +11,19 @@
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link id="favicon" rel="shortcut icon" sizes="any" href="/favicon.ico" />
<link
id="favicon"
rel="shortcut icon"
sizes="any"
href="<%=htmlWebpackPlugin.files.favicon%>"
/>
<link rel="manifest" href="/manifest.json" />
<link rel="manifest" href="../../../public/manifest.json" />
<!-- Tell the browser it's a PWA -->
<!-- <meta name="mobile-web-app-capable" content="yes" /> -->
<!-- Tell iOS it's a PWA -->
<!-- <meta name="apple-mobile-web-app-capable" content="yes" /> -->
<link rel="apple-touch-icon" href="/appIcon-180.png" />
<!-- <link rel="apple-touch-icon" href="../../../public/appIcon-180.png" /> -->
<!--
Notice the use of %PUBLIC_URL% in the tags above.
@ -36,10 +41,13 @@
content="app-id=com.onlyoffice.documents"
/>
<link rel="apple-touch-icon" href="./images/logo/favicon_general.ico" />
<link rel="android-touch-icon" href="./images/logo/favicon_general.ico" />
<link rel="apple-touch-icon" href="<%=htmlWebpackPlugin.files.favicon%>" />
<link
rel="android-touch-icon"
href="<%=htmlWebpackPlugin.files.favicon%>"
/>
<%= htmlWebpackPlugin.options.custom %>
<!-- <%= htmlWebpackPlugin.options.custom %> -->
<style type="text/css">
body {

View File

@ -11,7 +11,7 @@ import ScrollToTop from "./components/Layout/ScrollToTop";
import history from "@docspace/common/history";
import Toast from "@docspace/components/toast";
import toastr from "@docspace/components/toast/toastr";
import { updateTempContent } from "@docspace/common/utils";
import { getLogoFromPath, updateTempContent } from "@docspace/common/utils";
import { Provider as MobxProvider } from "mobx-react";
import ThemeProvider from "@docspace/components/theme-provider";
import store from "client/store";
@ -169,7 +169,7 @@ const Shell = ({ items = [], page = "home", ...rest }) => {
useEffect(() => {
if (!whiteLabelLogoUrls) return;
const favicon = whiteLabelLogoUrls[2]?.path?.light;
const favicon = getLogoFromPath(whiteLabelLogoUrls[2]?.path?.light);
let link = document.querySelector("link[rel~='icon']");
if (!link) {

View File

@ -107,29 +107,76 @@ const config = {
module: {
rules: [
/*{
test: /\.html$/i,
loader: "html-loader",
options: {
sources: {
urlFilter: (attribute, value, resourcePath) => {
// The `attribute` argument contains a name of the HTML attribute.
// The `value` argument contains a value of the HTML attribute.
// The `resourcePath` argument contains a path to the loaded HTML file.
// {
// test: /\.html$/i,
// loader: "html-loader",
// options: {
// // Disables attributes processing
// // sources: true,
if (
/manifest\.json$/.test(value) ||
/favicon\.ico$/.test(value) ||
/appIcon-180\.png$/.test(value)
) {
return false;
}
// sources: {
// list: [
// // All default supported tags and attributes
// "...",
// {
// tag: "link",
// attribute: "href",
// type: "src",
// filter: (tag, attribute, attributes, resourcePath) => {
// // The `tag` argument contains a name of the HTML tag.
// // The `attribute` argument contains a name of the HTML attribute.
// // The `attributes` argument contains all attributes of the tag.
// // The `resourcePath` argument contains a path to the loaded HTML file.
return true;
},
},
},
},*/
// const relValue = attributes.find((a) => a.name === "rel")
// .value;
// if (
// relValue === "shortcut icon" ||
// relValue === "manifest" ||
// relValue === "apple-touch-icon" ||
// relValue === "android-touch-icon"
// ) {
// return true;
// }
// if (/my-html\.html$/.test(resourcePath)) {
// return false;
// }
// if (!/stylesheet/i.test(attributes.rel)) {
// return false;
// }
// if (
// attributes.type &&
// attributes.type.trim().toLowerCase() !== "text/css"
// ) {
// return false;
// }
// return true;
// },
// },
// ],
// urlFilter: (attribute, value, resourcePath) => {
// // The `attribute` argument contains a name of the HTML attribute.
// // The `value` argument contains a value of the HTML attribute.
// // The `resourcePath` argument contains a path to the loaded HTML file.
// if (
// // /manifest\.json$/.test(value) ||
// /favicon\.ico$/.test(value) ||
// /appIcon-180\.png$/.test(value)
// ) {
// return true;
// }
// return false;
// },
// },
// },
// },
{
test: /\.(png|jpe?g|gif|ico)$/i,
type: "asset/resource",
@ -328,6 +375,8 @@ module.exports = (env, argv) => {
publicPath: homepage,
title: title,
base: `${homepage}/`,
favicon: "../../public/favicon.ico",
hash: true,
})
);
}