Skip to content

Commit

Permalink
build: reduce package size
Browse files Browse the repository at this point in the history
  • Loading branch information
kangfenmao committed Dec 23, 2024
1 parent 35fd5ae commit 7506d04
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 286 deletions.
16 changes: 12 additions & 4 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ files:
- '!packages'
- '!stats.html'
- '!*.md'
- '!**/*.{map,ts,tsx,jsx,less,scss,sass,css.d.ts,d.cts,d.mts,md,markdown,yaml,yml}'
- '!**/{test,tests,__tests__,coverage}/**'
- '!**/*.{spec,test}.{js,jsx,ts,tsx}'
- '!**/*.min.*.map'
- '!**/*.d.ts'
- '!**/{.DS_Store,Thumbs.db}'
- '!**/{LICENSE,LICENSE.txt,LICENSE-MIT.txt,*.LICENSE.txt,NOTICE.txt,README.md,CHANGELOG.md}'
- '!node_modules/rollup-plugin-visualizer'
- '!node_modules/js-tiktoken'
- '!node_modules/node_modules/pdf-parse/lib/pdf.js/v1.9.426'
- '!node_modules/node_modules/pdf-parse/lib/pdf.js/v1.10.88'
- '!node_modules/node_modules/pdf-parse/lib/pdf.js/v2.0.550'
- '!node_modules/pdf-parse/lib/pdf.js/{v1.9.426,v1.10.88,v2.0.550}'
- '!node_modules/mammoth/{mammoth.browser.js,mammoth.browser.min.js}'
- '!node_modules/html2canvas/dist/{html2canvas.min.js,html2canvas.esm.js}'

asarUnpack:
- resources/**
Expand Down Expand Up @@ -70,7 +77,8 @@ publish:
url: https://cherrystudio.ocool.online
electronDownload:
mirror: https://npmmirror.com/mirrors/electron/
afterSign: scripts/notarize.js
afterPack: scripts/removeLocales.js
# afterSign: scripts/notarize.js
releaseInfo:
releaseNotes: |
增加小程序快捷入口
Expand Down
6 changes: 5 additions & 1 deletion electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default defineConfig({
build: {
rollupOptions: {
external: ['@libsql/client']
}
},
minify: true
}
},
preload: {
Expand All @@ -51,6 +52,9 @@ export default defineConfig({
},
optimizeDeps: {
exclude: ['chunk-7UIZINC5.js', 'chunk-7OJJKI46.js']
},
build: {
minify: true
}
}
})
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"@llm-tools/embedjs-openai": "^0.1.25",
"@types/react-infinite-scroll-component": "^5.0.0",
"adm-zip": "^0.5.16",
"apache-arrow": "^18.0.0",
"docx": "^9.0.2",
"electron-log": "^5.1.5",
"electron-store": "^8.2.0",
Expand Down
58 changes: 58 additions & 0 deletions scripts/removeLocales.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const fs = require('fs')
const path = require('path')

exports.default = async function (context) {
const platform = context.packager.platform.name

// 根据平台确定 locales 目录位置
let resourceDirs = []
if (platform === 'mac') {
// macOS 的语言文件位置
resourceDirs = [
path.join(context.appOutDir, 'Cherry Studio.app', 'Contents', 'Resources'),
path.join(
context.appOutDir,
'Cherry Studio.app',
'Contents',
'Frameworks',
'Electron Framework.framework',
'Resources'
)
]
} else {
// Windows 和 Linux 的语言文件位置
resourceDirs = [path.join(context.appOutDir, 'locales')]
}

// 处理每个资源目录
for (const resourceDir of resourceDirs) {
if (!fs.existsSync(resourceDir)) {
console.log(`Resource directory not found: ${resourceDir}, skipping...`)
continue
}

// 读取所有文件和目录
const items = fs.readdirSync(resourceDir)

// 遍历并删除不需要的语言文件
for (const item of items) {
if (platform === 'mac') {
// 在 macOS 上检查 .lproj 目录
if (item.endsWith('.lproj') && !item.match(/^(en|zh|ru)/)) {
const dirPath = path.join(resourceDir, item)
fs.rmSync(dirPath, { recursive: true, force: true })
console.log(`Removed locale directory: ${item} from ${resourceDir}`)
}
} else {
// 其他平台处理 .pak 文件
if (!item.match(/^(en|zh|ru)/)) {
const filePath = path.join(resourceDir, item)
fs.unlinkSync(filePath)
console.log(`Removed locale file: ${item} from ${resourceDir}`)
}
}
}
}

console.log('Locale cleanup completed!')
}
Binary file modified src/renderer/src/assets/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 0 additions & 55 deletions src/renderer/src/assets/images/logo/cherry-hr.svg

This file was deleted.

Loading

0 comments on commit 7506d04

Please sign in to comment.