Electron Builder AfterPack configuration

Ganesh Rathinavel
1 min readJan 26, 2019

--

Introduction

There isn’t much information available on Electron Builder AfterPack configuration. I have created a sample code which cleans the junk locale directories from the packaged electron app. This was originally implemented inside OpenMTP — Advanced Android File Transfer Application for macOS.

Implementation

  • Add the below lines inside your package.json file
"build": {
"afterPack": "./internals/scripts/AfterPack.js"
}
  • Create a file ./internals/scripts/AfterPack.js and add the below code
'use strict';const path = require('path');
const glob = require('glob');
const fs = require('fs-extra');
exports.default = context => {
const lprojRegEx = /(en)\.lproj/g;
const APP_NAME = context.packager.appInfo.productFilename;
const APP_OUT_DIR = context.appOutDir;
const PLATFORM = context.packager.platform.name;
const cwd = path.join(`${APP_OUT_DIR}`, `${APP_NAME}.app/Contents/Resources`);
const lproj = glob.sync('*.lproj', { cwd });
const _promises = [];
switch (PLATFORM) {
case 'mac':
lproj.forEach(dir => {
if (!lprojRegEx.test(dir)) {
_promises.push(fs.remove(path.join(cwd, dir)));
}
});
break;
default:
break;
}
return Promise.all(_promises);
};

More repos

License

tutorial-electron-afterpack-script is released under MIT License.

Copyright © 2018-Present Ganesh Rathinavel

--

--