Skip to content

Commit

Permalink
chore: reduce electron asar size
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Nov 11, 2024
1 parent ab28156 commit 6eed2c4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 41 deletions.
2 changes: 1 addition & 1 deletion apps/renderer/src/modules/settings/tabs/data-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const AppCacheLimit = () => {
<Label className="center flex">
{t("data_control.app_cache_limit.label")}

<span className="center ml-2 flex shrink-0 gap-1 text-xs text-gray-500">
<span className="center ml-2 flex shrink-0 gap-1 text-xs opacity-60">
<span>({cacheSize}M</span> /{" "}
<span className="center flex shrink-0">
{cacheLimit ? `${cacheLimit}M` : InfinitySymbol})
Expand Down
14 changes: 13 additions & 1 deletion electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { resolve } from "node:path"
import { defineConfig } from "electron-vite"

import { viteRenderBaseConfig } from "./configs/vite.render.config"
import { cleanupUnnecessaryFilesPlugin } from "./plugins/vite/cleanup"
import { createPlatformSpecificImportPlugin } from "./plugins/vite/specific-import"

export default defineConfig({
Expand Down Expand Up @@ -42,7 +43,18 @@ export default defineConfig({
renderer: {
...viteRenderBaseConfig,

plugins: [...viteRenderBaseConfig.plugins, createPlatformSpecificImportPlugin(true)],
plugins: [
...viteRenderBaseConfig.plugins,
createPlatformSpecificImportPlugin(true),
cleanupUnnecessaryFilesPlugin([
"og-image.png",
"icon-512x512.png",
"opengraph-image.png",
"favicon.ico",
"icon-192x192.png",
"favicon-dev.ico",
]),
],

root: "apps/renderer",
build: {
Expand Down
23 changes: 23 additions & 0 deletions plugins/vite/cleanup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import fs from "node:fs"
import path from "node:path"

import type { Plugin, ResolvedConfig } from "vite"

export function cleanupUnnecessaryFilesPlugin(files: string[]): Plugin {
let config: ResolvedConfig
return {
name: "cleanup-unnecessary",
enforce: "post",
configResolved(resolvedConfig) {
config = resolvedConfig
},
async generateBundle(_options) {
await Promise.all(
files.map((file) => {
console.info(`Deleting ${path.join(config.build.outDir, file)}`)
return fs.promises.unlink(path.join(config.build.outDir, file))
}),
)
},
}
}
39 changes: 0 additions & 39 deletions plugins/vite/custom-asset.ts

This file was deleted.

0 comments on commit 6eed2c4

Please sign in to comment.