mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-04-27 07:40:55 -07:00
fix: asar packages electron framework, causing it become huge
This commit is contained in:
parent
03caf533ad
commit
0671c643a0
3 changed files with 38 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
|||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||
const packageJson = require('./package.json');
|
||||
const beforeAsar = require('./scripts/beforeAsar')
|
||||
|
||||
const { version, description } = packageJson;
|
||||
|
||||
|
|
@ -30,6 +31,7 @@ const config = {
|
|||
},
|
||||
appBundleId: 'com.tidgi',
|
||||
afterPrune: ['scripts/afterPack.js'],
|
||||
beforeAsar: [beforeAsar.default],
|
||||
},
|
||||
makers: [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ const exec = util.promisify(require('child_process').exec);
|
|||
* Specific which lproj you want to keep
|
||||
*/
|
||||
const keepingLprojRegEx = /(en|zh_CN)\.lproj/g;
|
||||
const shell = process.platform === 'win32' ? true : process.platform === 'darwin' ? '/bin/zsh' : '/bin/bash';
|
||||
/**
|
||||
*
|
||||
* @param {*} buildPath /var/folders/qj/7j0zx32d0l75zmnrl1w3m3b80000gn/T/electron-packager/darwin-x64/TidGi-darwin-x64/Electron.app/Contents/Resources/app
|
||||
|
|
|
|||
36
scripts/beforeAsar.js
Normal file
36
scripts/beforeAsar.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable unicorn/import-style */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
/* eslint-disable security/detect-child-process */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
/* eslint-disable unicorn/prevent-abbreviations */
|
||||
/**
|
||||
* Remove all .lproj files
|
||||
* Based on https://ganeshrvel.medium.com/electron-builder-afterpack-configuration-5c2c986be665
|
||||
* Adapted for electron forge https://github.com/electron-userland/electron-forge/issues/2248
|
||||
*/
|
||||
const path = require('path');
|
||||
const glob = require('glob');
|
||||
const fs = require('fs-extra');
|
||||
const util = require('util');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} buildPath /var/folders/qj/7j0zx32d0l75zmnrl1w3m3b80000gn/T/electron-packager/darwin-x64/TidGi-darwin-x64/Electron.app/Contents/Resources/app
|
||||
* @param {*} electronVersion 12.0.6
|
||||
* @param {*} platform darwin
|
||||
* @param {*} arch x64
|
||||
* @returns
|
||||
*/
|
||||
exports.default = async (buildPath, electronVersion, platform, arch, callback) => {
|
||||
const cwd = path.resolve(buildPath, '..');
|
||||
|
||||
/** delete useless lproj files to make it clean */
|
||||
const duplicatedLocalization = glob.sync('**/.webpack/main/localization/**', { cwd });
|
||||
const duplicatedElectronDist = glob.sync('**/.webpack/main/native_modules/dist/**', { cwd });
|
||||
const pathsToRemove = [...duplicatedLocalization, ...duplicatedElectronDist].map((directory) => path.join(cwd, directory));
|
||||
await Promise.all(pathsToRemove.map((directory) => fs.remove(directory)));
|
||||
|
||||
/** complete this hook */
|
||||
callback();
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue