DnsChanger / dnsChanger-desktop

DNS Changer for Windows, Linux, Mac operating systems
https://dnschanger.github.io/
MIT License
478 stars 39 forks source link

کاهش حجم برنامه #6

Closed sajjadmrx closed 1 year ago

alishefaee commented 1 year ago

I used electron-builder instead of electron-forge and I did following tricks to reduce size:

  1. The reason of this problem is, when you package the software, all packages (like redux, react ...) in node_modules is included in installer exe. The solution is to devide your software in two section (or project). elecron part and react part. and delete all front packages from electron related package.json file. And then build your react and put production code it electron app.

  2. Add "afterPack": "./utils/removeLocales.js" to delete all extra locales.

    "build": {
    "appId": "com.electron.electron-serial",
    "productName": "electron-serial",
    "afterPack": "./utils/removeLocales.js",

    removeLocales.js:

    //https://www.electron.build/configuration/configuration#afterpack
    exports.default = async function(context) {
    //console.log(context)
    var fs = require('fs');
    var localeDir = context.appOutDir+'/locales/';
    
    fs.readdir(localeDir, function(err, files){
        //files is array of filenames (basename form)
        if(!(files && files.length)) return;
        for (var i = 0, len = files.length; i < len; i++) {
            var match = files[i].match(/en-US\.pak/);
            if(match === null){
                fs.unlinkSync(localeDir+files[i]);
            }
        }
    });
    }
sajjadmrx commented 1 year ago

I used electron-builder instead of electron-forge and I did following tricks to reduce size:

  1. The reason of this problem is, when you package the software, all packages (like redux, react ...) in node_modules is included in installer exe. The solution is to devide your software in two section (or project). elecron part and react part. and delete all front packages from electron related package.json file. And then build your react and put production code it electron app.
  2. Add "afterPack": "./utils/removeLocales.js" to delete all extra locales.
  "build": {
    "appId": "com.electron.electron-serial",
    "productName": "electron-serial",
    "afterPack": "./utils/removeLocales.js",

removeLocales.js:

//https://www.electron.build/configuration/configuration#afterpack
exports.default = async function(context) {
    //console.log(context)
    var fs = require('fs');
    var localeDir = context.appOutDir+'/locales/';

    fs.readdir(localeDir, function(err, files){
        //files is array of filenames (basename form)
        if(!(files && files.length)) return;
        for (var i = 0, len = files.length; i < len; i++) {
            var match = files[i].match(/en-US\.pak/);
            if(match === null){
                fs.unlinkSync(localeDir+files[i]);
            }
        }
    });
}

hey, What was the output size? and can you send pull request?

alishefaee commented 1 year ago

I got 70 mb for windows .msi file (I think it's normal for electron app). I do not have exprience with electron-forge as it uses very specific starter boilerplate.