fix: remove wdyr in prod

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei 2024-11-14 22:50:03 +08:00
parent 9b350741d1
commit 70e3b72b0a
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
5 changed files with 37 additions and 9 deletions

View File

@ -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"
@ -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

View File

@ -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,
})
}

View File

@ -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",
@ -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"

View File

@ -239,6 +239,9 @@ importers:
vite:
specifier: ^5.4.10
version: 5.4.10(@types/node@22.8.7)(lightningcss@1.27.0)(terser@5.35.0)
vite-bundle-analyzer:
specifier: 0.13.1
version: 0.13.1
vite-plugin-mkcert:
specifier: 1.17.6
version: 1.17.6(vite@5.4.10(@types/node@22.8.7)(lightningcss@1.27.0)(terser@5.35.0))
@ -3430,8 +3433,8 @@ packages:
'@radix-ui/react-avatar@1.1.1':
resolution: {integrity: sha512-eoOtThOmxeoizxpX6RiEsQZ2wj5r4+zoeqAwO0cBaFQGjJwIH3dIX0OCxNrCyrrdxG+vBweMETh3VziQG7c1kw==}
peerDependencies:
'@types/react': npm:types-react@19.0.0-rc.1
'@types/react-dom': npm:types-react-dom@19.0.0-rc.1
'@types/react': '*'
'@types/react-dom': '*'
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
@ -3601,8 +3604,8 @@ packages:
'@radix-ui/react-label@2.1.0':
resolution: {integrity: sha512-peLblDlFw/ngk3UWq0VnYaOLy6agTZZ+MUO/WhVfm14vJGML+xH4FAl2XQGLqdefjNb7ApRg6Yn7U42ZhmYXdw==}
peerDependencies:
'@types/react': npm:types-react@19.0.0-rc.1
'@types/react-dom': npm:types-react-dom@19.0.0-rc.1
'@types/react': '*'
'@types/react-dom': '*'
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
@ -10480,6 +10483,9 @@ packages:
vfile@6.0.3:
resolution: {integrity: sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==}
vite-bundle-analyzer@0.13.1:
resolution: {integrity: sha512-471KXy0cq8L9voQnkLwintkDewhUDxSOUfUq5qgCXalORVmMt4W5JbcLVR6ybEHG6K83afs9/pD7LAlnJYS4mQ==}
vite-node@2.0.5:
resolution: {integrity: sha512-LdsW4pxj0Ot69FAoXZ1yTnA9bjGohr2yNBU7QKRxpz8ITSkhuDl6h3zS/tvgz4qrNjeRnvrWeXQ8ZF7Um4W00Q==}
engines: {node: ^18.0.0 || >=20.0.0}
@ -22023,6 +22029,8 @@ snapshots:
'@types/unist': 3.0.3
vfile-message: 4.0.2
vite-bundle-analyzer@0.13.1: {}
vite-node@2.0.5(@types/node@22.8.7)(lightningcss@1.27.0)(terser@5.35.0):
dependencies:
cac: 6.7.14

View File

@ -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"
@ -149,6 +150,7 @@ export default ({ mode }) => {
createPlatformSpecificImportPlugin(false),
manifestPlugin(),
htmlPlugin(typedEnv),
process.env.analyzer && analyzer(),
],
define: {