Skip to content

Commit

Permalink
refactor: 优化打包,尽可能将数据放入asar
Browse files Browse the repository at this point in the history
参见electron/electron#33216
electron已经支持从asar中启动worker threads
  • Loading branch information
nzh63 committed Oct 22, 2023
1 parent b8503f9 commit 4c56053
Show file tree
Hide file tree
Showing 11 changed files with 1,360 additions and 1,221 deletions.
252 changes: 0 additions & 252 deletions config/antdv-resolver.ts

This file was deleted.

14 changes: 13 additions & 1 deletion config/rollup.workers.config.ts
Expand Up @@ -7,6 +7,7 @@ import json from '@rollup/plugin-json';
import alias from '@rollup/plugin-alias';
import { wasm } from '@rollup/plugin-wasm';
import esbuild from 'rollup-plugin-esbuild';
import copy from 'rollup-plugin-copy';
import log from './LogPlugin';
import native from './NativePlugin';
import devSpeedup from './DevSpeedupPlugin';
Expand Down Expand Up @@ -75,14 +76,25 @@ export default (mode = 'production') => ({
}
}
})
: null,
mode === 'production'
? copy({
targets: [{
src: [
'node_modules/tesseract.js-core/tesseract-core.wasm',
'node_modules/tesseract.js-core/tesseract-core-simd.wasm'
],
dest: path.join(__dirname, '../dist/workers')
}]
})
: null
],
input: workerEntries,
output: {
dir: path.join(__dirname, '../dist/workers'),
entryFileNames: (chunkInfo) => {
const workerBase = path.join(__dirname, '../src/workers').replace(/\\/g, '/');
const facadeModuleId = chunkInfo.facadeModuleId.replace(/\\/g, '/');
const facadeModuleId = (chunkInfo.facadeModuleId ?? '').replace(/\\/g, '/');
if (facadeModuleId.startsWith(workerBase)) {
const reg = new RegExp(`^${workerBase}/(.*?)/`);
const workerName = (reg.exec(facadeModuleId) ?? [])[1];
Expand Down
4 changes: 2 additions & 2 deletions config/vite.render.config.ts
Expand Up @@ -5,7 +5,7 @@ import glob from 'glob';
import nodeResolve from '@rollup/plugin-node-resolve';
import log from './LogPlugin';
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from './antdv-resolver';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';

import builtinModules from 'builtin-modules/static';
const license = require('rollup-plugin-license');
Expand Down Expand Up @@ -54,7 +54,7 @@ export default defineConfig(({ mode } = { command: 'build', mode: 'production' }
disableLog: mode === 'production'
}),
vue(),
Components({ resolvers: [AntDesignVueResolver({ importStyle: false, resolveIcons: true })] }),
Components({ dts: false, resolvers: [AntDesignVueResolver({ importStyle: false, resolveIcons: true })] }),
nodeResolve({ extensions: ['.js', '.ts', '.node'], browser: true }),
mode === 'production'
? license({
Expand Down
3 changes: 0 additions & 3 deletions electron-builder.yml
Expand Up @@ -23,9 +23,6 @@ files:
- "!**/{appveyor.yml,.travis.yml,circle.yml}"
- "!**/{npm-debug.log,yarn.lock,.yarn-integrity,.yarn-metadata.json}"
- "!node_modules/sharp/vendor"
asarUnpack:
- dist/workers/**/*
- node_modules/tesseract.js-core/**/*
buildDependenciesFromSource: true
extraResources:
- from: ./static
Expand Down
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -27,8 +27,7 @@
"type-check": "tsc --noEmit"
},
"dependencies": {
"sharp": "^0.30.5",
"tesseract.js-core": "^2.2.0"
"sharp": "^0.32.6"
},
"devDependencies": {
"@ant-design/icons-vue": "^6.0.1",
Expand All @@ -43,7 +42,6 @@
"@types/lodash-es": "^4.17.4",
"@types/mocha": "^9.0.0",
"@types/node": "^16.11.2",
"@types/sharp": "^0.28.0",
"@types/shell-quote": "^1.7.1",
"@types/uuid": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^5.27.1",
Expand Down Expand Up @@ -79,16 +77,18 @@
"node-gyp": "^9.0.0",
"remove": "^0.1.5",
"rollup": "^2.71.1",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-esbuild": "^4.9.1",
"rollup-plugin-license": "^2.7.0",
"rollup-plugin-typescript2": "^0.31.2",
"shell-quote": "^1.7.4",
"source-map-support": "^0.5.19",
"tencentcloud-sdk-nodejs": "^4.0.333",
"tesseract.js": "^2.1.5",
"tesseract.js": "^5.0.2",
"tesseract.js-core": "^5.0.0",
"ts-node": "^10.7.0",
"typescript": "^4.6.4",
"unplugin-vue-components": "^0.16.0",
"unplugin-vue-components": "^0.25.2",
"uuid": "^8.3.2",
"vite": "^2.9.16",
"vue": "^3.2.33",
Expand Down
4 changes: 2 additions & 2 deletions src/main/paths.ts
Expand Up @@ -8,9 +8,9 @@ if (import.meta.env.DEV) {
}

export const __assets = join(__dirname, '../../assets').replace(/\\/g, '/');
export let __workers:string;
export let __workers: string;
if (import.meta.env.DEV) {
__workers = join(__dirname, '../workers').replace(/\\/g, '/');
} else {
__workers = join(process.resourcesPath, 'app.asar.unpacked/dist/workers').replace(/\\/g, '/');
__workers = join(process.resourcesPath, 'app.asar/dist/workers').replace(/\\/g, '/');
}
1 change: 0 additions & 1 deletion src/main/providers/index.ts
@@ -1,4 +1,3 @@

export { BaseProvider, BaseProviderConfig } from './BaseProvider';
export { TranslateProvider } from './TranslateProvider';
export { TtsProvider } from './TtsProvider';
Expand Down
19 changes: 0 additions & 19 deletions src/type/segmenter.d.ts

This file was deleted.

0 comments on commit 4c56053

Please sign in to comment.