Skip to content

Commit

Permalink
fix: remove wdyr in prod
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Nov 14, 2024
1 parent 9b35074 commit 70e3b72
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
20 changes: 19 additions & 1 deletion apps/renderer/src/initialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { authConfigManager } from "@hono/auth-js/react"
import { repository } from "@pkg"
import { enableMapSet } from "immer"

import { isElectronBuild } from "~/constants"
import { isDev, isElectronBuild } from "~/constants"
import { browserDB } from "~/database"
import { initI18n } from "~/i18n"
import { settingSyncQueue } from "~/modules/settings/helper/sync-queue"
Expand Down Expand Up @@ -40,6 +40,24 @@ declare global {

export const initializeApp = async () => {
appLog(`${APP_NAME}: Next generation information browser`, repository.url)

if (isDev) {
const favicon = await import("~/../public/favicon-dev.ico?url")

const url = new URL(favicon.default, import.meta.url).href

// Change favicon
const $icon = document.head.querySelector("link[rel='icon']")
if ($icon) {
$icon.setAttribute("href", url)
} else {
const icon = document.createElement("link")
icon.setAttribute("rel", "icon")
icon.setAttribute("href", url)
document.head.append(icon)
}
}

appLog(`Initialize ${APP_NAME}...`)
window.version = APP_VERSION

Expand Down
5 changes: 2 additions & 3 deletions apps/renderer/src/wdyr.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable @typescript-eslint/triple-slash-reference */
/// <reference types="@welldone-software/why-did-you-render" />
import whyDidYouRender from "@welldone-software/why-did-you-render"
import * as React from "react"

if (import.meta.env.DEV) {
whyDidYouRender(React as any, {
const whyDidYouRender = await import("@welldone-software/why-did-you-render")
whyDidYouRender.default(React as any, {
trackAllPureComponents: true,
})
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"main": "./dist/main/index.js",
"scripts": {
"analyze:web": "npx vite-bundle-visualizer",
"analyze:web": "analyzer=1 vite build",
"build": "electron-vite build && electron-forge make",
"build:macos": "electron-vite build && electron-forge make --arch=x64 --platform=darwin && electron-forge make --arch=arm64 --platform=darwin && tsx scripts/merge-yml.ts",
"build:web": "rm -rf out/web && vite build",
Expand Down Expand Up @@ -108,6 +108,7 @@
"typescript": "5.6.3",
"unplugin-ast": "^0.11.0",
"vite": "^5.4.10",
"vite-bundle-analyzer": "0.13.1",
"vite-plugin-mkcert": "1.17.6",
"vite-tsconfig-paths": "5.0.1",
"vitest": "2.0.5"
Expand Down
16 changes: 12 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { minify as htmlMinify } from "html-minifier-terser"
import { cyan, dim, green } from "kolorist"
import type { PluginOption, ViteDevServer } from "vite"
import { defineConfig, loadEnv } from "vite"
import { analyzer } from "vite-bundle-analyzer"
import mkcert from "vite-plugin-mkcert"

import { viteRenderBaseConfig } from "./configs/vite.render.config"
Expand Down Expand Up @@ -149,6 +150,7 @@ export default ({ mode }) => {
createPlatformSpecificImportPlugin(false),
manifestPlugin(),
htmlPlugin(typedEnv),
process.env.analyzer && analyzer(),
],

define: {
Expand Down

0 comments on commit 70e3b72

Please sign in to comment.