pref: reduce main bundle size (#267)
* perf: reduce bundle size Signed-off-by: Innei <i@innei.in> * chore: fix shiki deps Signed-off-by: Innei <i@innei.in> --------- Signed-off-by: Innei <i@innei.in>
This commit is contained in:
@@ -4,6 +4,7 @@ import { resolve } from "node:path"
|
||||
import { sentryVitePlugin } from "@sentry/vite-plugin"
|
||||
import react from "@vitejs/plugin-react"
|
||||
import { defineConfig } from "electron-vite"
|
||||
import { prerelease } from "semver"
|
||||
|
||||
import { getGitHash } from "./scripts/lib"
|
||||
|
||||
@@ -72,6 +73,10 @@ export default defineConfig({
|
||||
|
||||
DEBUG: process.env.DEBUG === "true",
|
||||
ELECTRON: "true",
|
||||
|
||||
RELEASE_CHANNEL: JSON.stringify(
|
||||
(prerelease(pkg.version)?.[0] as string) || "stable",
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
+5
-3
@@ -14,6 +14,7 @@
|
||||
},
|
||||
"main": "./dist/main/index.js",
|
||||
"scripts": {
|
||||
"analyze:web": "rm -rf out/web && ANALYZER=1 vite build",
|
||||
"build": "npm run typecheck && electron-vite build --outDir=dist && electron-forge make",
|
||||
"build:macos": "npm run typecheck && electron-vite build --outDir=dist && electron-forge make --arch=universal --platform=darwin",
|
||||
"build:web": "rm -rf out/web && vite build",
|
||||
@@ -64,7 +65,7 @@
|
||||
"@sentry/electron": "5.4.0",
|
||||
"@sentry/react": "8.27.0",
|
||||
"@sentry/vite-plugin": "2.22.3",
|
||||
"@shikijs/transformers": "1.15.1",
|
||||
"@shikijs/transformers": "1.16.1",
|
||||
"@t3-oss/env-core": "^0.11.1",
|
||||
"@tanstack/query-sync-storage-persister": "5.53.1",
|
||||
"@tanstack/react-query": "5.53.1",
|
||||
@@ -125,7 +126,7 @@
|
||||
"remark-parse": "11.0.0",
|
||||
"remark-rehype": "11.1.0",
|
||||
"semver": "7.6.3",
|
||||
"shiki": "1.15.1",
|
||||
"shiki": "1.16.1",
|
||||
"sonner": "^1.5.0",
|
||||
"swiper": "11.1.11",
|
||||
"tailwind-merge": "2.5.2",
|
||||
@@ -162,6 +163,7 @@
|
||||
"@vercel/ncc": "0.38.1",
|
||||
"@vitejs/plugin-legacy": "5.4.2",
|
||||
"@vitejs/plugin-react": "^4.3.1",
|
||||
"cssnano": "7.0.5",
|
||||
"drizzle-orm": "0.33.0",
|
||||
"electron": "32.0.1",
|
||||
"electron-devtools-installer": "3.2.0",
|
||||
@@ -178,13 +180,13 @@
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"rimraf": "6.0.1",
|
||||
"rollup-plugin-visualizer": "5.12.0",
|
||||
"shx": "^0.3.4",
|
||||
"simple-git-hooks": "2.11.1",
|
||||
"tailwindcss": "3.4.10",
|
||||
"tailwindcss-animate": "1.0.7",
|
||||
"typescript": "^5.5.4",
|
||||
"vite": "^5.4.2",
|
||||
"vite-bundle-analyzer": "0.10.6",
|
||||
"vite-plugin-mkcert": "1.17.6",
|
||||
"vite-tsconfig-paths": "5.0.1",
|
||||
"vitest": "2.0.5"
|
||||
|
||||
Generated
+453
-230
File diff suppressed because it is too large
Load Diff
@@ -2,5 +2,7 @@ module.exports = {
|
||||
plugins: {
|
||||
"tailwindcss": {},
|
||||
"tailwindcss/nesting": {},
|
||||
|
||||
...(process.env.NODE_ENV === "production" ? { cssnano: {} } : {}),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ function App() {
|
||||
const windowsElectron = window.electron && getOS() === "Windows"
|
||||
return (
|
||||
<RootProviders>
|
||||
|
||||
{window.electron && (
|
||||
<div
|
||||
className={cn(
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { attachOpenInEditor } from "@renderer/lib/dev"
|
||||
import { getNewIssueUrl } from "@renderer/lib/issues"
|
||||
import { clearLocalPersistStoreData } from "@renderer/store/utils/clear"
|
||||
import { captureException } from "@sentry/react"
|
||||
import { useEffect, useRef } from "react"
|
||||
import { isRouteErrorResponse, useNavigate, useRouteError } from "react-router-dom"
|
||||
import {
|
||||
isRouteErrorResponse,
|
||||
useNavigate,
|
||||
useRouteError,
|
||||
} from "react-router-dom"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { Button } from "../ui/button"
|
||||
@@ -23,9 +28,8 @@ export function ErrorElement() {
|
||||
"Error handled by React Router default ErrorBoundary:",
|
||||
error,
|
||||
)
|
||||
import("@sentry/react").then(({ captureException }) => {
|
||||
captureException(error)
|
||||
})
|
||||
|
||||
captureException(error)
|
||||
}, [error])
|
||||
|
||||
const reloadRef = useRef(false)
|
||||
@@ -74,10 +78,11 @@ export function ErrorElement() {
|
||||
>
|
||||
Reset Local Database
|
||||
</Button>
|
||||
<Button onClick={() => {
|
||||
navigate("/")
|
||||
window.location.reload()
|
||||
}}
|
||||
<Button
|
||||
onClick={() => {
|
||||
navigate("/")
|
||||
window.location.reload()
|
||||
}}
|
||||
>
|
||||
Reload
|
||||
</Button>
|
||||
@@ -114,7 +119,6 @@ export const FallbackIssue = ({
|
||||
"```",
|
||||
stack,
|
||||
"```",
|
||||
|
||||
].join("\n"),
|
||||
label: "bug",
|
||||
})}
|
||||
|
||||
@@ -9,7 +9,6 @@ import { useIsomorphicLayoutEffect } from "foxact/use-isomorphic-layout-effect"
|
||||
import type { FC } from "react"
|
||||
import {
|
||||
useInsertionEffect,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
@@ -21,17 +20,20 @@ import type {
|
||||
DynamicImportThemeRegistration,
|
||||
HighlighterCore,
|
||||
} from "shiki"
|
||||
import { createHighlighterCore } from "shiki/core"
|
||||
import { default as getWasm } from "shiki/wasm"
|
||||
import {
|
||||
createHighlighterCoreSync,
|
||||
createJavaScriptRegexEngine,
|
||||
} from "shiki/core"
|
||||
|
||||
import { CopyButton } from "../copy-button"
|
||||
import { shikiTransformers } from "./shared"
|
||||
import styles from "./shiki.module.css"
|
||||
|
||||
const shikiPromise = createHighlighterCore({
|
||||
themes: [import("shiki/themes/github-dark.mjs")],
|
||||
const js = createJavaScriptRegexEngine()
|
||||
const shiki = createHighlighterCoreSync({
|
||||
themes: [],
|
||||
langs: [],
|
||||
loadWasm: getWasm,
|
||||
engine: js,
|
||||
})
|
||||
|
||||
export interface ShikiProps {
|
||||
@@ -53,21 +55,8 @@ let langModule: Record<
|
||||
let themeModule: Record<BundledTheme, DynamicImportThemeRegistration> | null =
|
||||
null
|
||||
let bundledLanguagesKeysSet: Set<string> | null = null
|
||||
let resolvedShiki: HighlighterCore | null = null
|
||||
|
||||
shikiPromise.then((shiki) => {
|
||||
resolvedShiki = shiki
|
||||
})
|
||||
export const ShikiHighLighter: FC<ShikiProps> = (props) => {
|
||||
const [shiki, setShiki] = useState(resolvedShiki)
|
||||
|
||||
useLayoutEffect(() => {
|
||||
shikiPromise.then((shiki) => {
|
||||
resolvedShiki = shiki
|
||||
setShiki(shiki)
|
||||
})
|
||||
}, [])
|
||||
|
||||
if (!shiki) {
|
||||
const { code, className } = props
|
||||
return (
|
||||
@@ -230,7 +219,7 @@ const ShikiCode: FC<
|
||||
// console.error(err)
|
||||
return null
|
||||
}
|
||||
}, [code, language, codeTheme])
|
||||
}, [shiki, code, language, codeTheme])
|
||||
|
||||
if (!rendered) {
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import * as semver from "semver"
|
||||
|
||||
import { getStorageNS } from "../lib/ns"
|
||||
import { getStorageNS } from "@renderer/lib/ns"
|
||||
|
||||
/// Feed
|
||||
export const FEED_COLLECTION_LIST = "collections"
|
||||
@@ -11,7 +9,3 @@ export const QUERY_PERSIST_KEY = getStorageNS("REACT_QUERY_OFFLINE_CACHE")
|
||||
export const ROUTE_FEED_PENDING = "all"
|
||||
export const ROUTE_ENTRY_PENDING = "pending"
|
||||
export const ROUTE_FEED_IN_FOLDER = "folder-"
|
||||
|
||||
export const channel = import.meta.env.DEV ?
|
||||
"development" :
|
||||
(semver.prerelease(APP_VERSION)?.[0] as string) || "stable"
|
||||
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
/// <reference types="vite/client" />
|
||||
declare const APP_VERSION: string
|
||||
declare const APP_NAME: string
|
||||
declare const RELEASE_CHANNEL: string
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { env } from "@env"
|
||||
import { version } from "@pkg"
|
||||
import { whoami } from "@renderer/atoms/user"
|
||||
import { channel } from "@renderer/constants"
|
||||
import { useEffect } from "react"
|
||||
import {
|
||||
createRoutesFromChildren,
|
||||
@@ -21,7 +20,7 @@ export const initSentry = async () => {
|
||||
])
|
||||
Sentry.init({
|
||||
dsn: env.VITE_SENTRY_DSN,
|
||||
environment: channel,
|
||||
environment: RELEASE_CHANNEL,
|
||||
integrations: [
|
||||
Sentry.moduleMetadataIntegration(),
|
||||
Sentry.httpClientIntegration(),
|
||||
|
||||
@@ -3,7 +3,6 @@ import { apiClient } from "@renderer/lib/api-fetch"
|
||||
import { defineQuery } from "@renderer/lib/defineQuery"
|
||||
import type { SupportedLanguages } from "@renderer/models"
|
||||
import type { FlatEntryModel } from "@renderer/store/entry"
|
||||
import { franc } from "franc-min"
|
||||
|
||||
const LanguageMap: Record<
|
||||
SupportedLanguages,
|
||||
@@ -48,6 +47,7 @@ export const ai = {
|
||||
if (extraFields) {
|
||||
fields = [...fields, ...extraFields]
|
||||
}
|
||||
const { franc } = await import("franc-min")
|
||||
|
||||
fields = fields.filter((field) => {
|
||||
if (entry.settings?.translation && entry.entries[field]) {
|
||||
|
||||
+7
-2
@@ -6,9 +6,10 @@ import { sentryVitePlugin } from "@sentry/vite-plugin"
|
||||
import legacy from "@vitejs/plugin-legacy"
|
||||
import react from "@vitejs/plugin-react"
|
||||
import { cyan, dim, green } from "kolorist"
|
||||
import { visualizer } from "rollup-plugin-visualizer"
|
||||
import { prerelease } from "semver"
|
||||
import type { PluginOption, ViteDevServer } from "vite"
|
||||
import { defineConfig, loadEnv } from "vite"
|
||||
import { analyzer } from "vite-bundle-analyzer"
|
||||
import mkcert from "vite-plugin-mkcert"
|
||||
|
||||
import { getGitHash } from "./scripts/lib"
|
||||
@@ -84,7 +85,7 @@ const vite = ({ mode }) => {
|
||||
}),
|
||||
|
||||
devPrint(),
|
||||
process.env.ANALYZER && visualizer({ open: true }),
|
||||
process.env.ANALYZER && analyzer(),
|
||||
],
|
||||
define: {
|
||||
APP_VERSION: JSON.stringify(pkg.version),
|
||||
@@ -95,6 +96,10 @@ const vite = ({ mode }) => {
|
||||
process.env.VERCEL_GIT_COMMIT_SHA || getGitHash(),
|
||||
),
|
||||
|
||||
RELEASE_CHANNEL: JSON.stringify(
|
||||
(prerelease(pkg.version)?.[0] as string) || "stable",
|
||||
),
|
||||
|
||||
DEBUG: process.env.DEBUG === "true",
|
||||
ELECTRON: "false",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user