javascript 电子封装:减小封装尺寸

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47597283/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 07:29:52  来源:igfitidea点击:

electron package: reduce the package size

javascriptelectronelectron-packager

提问by ar099968

I made a simple Electronapp:

我做了一个简单的电子应用程序:

main.js

主文件

const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')

let win

function createWindow () {
  win = new BrowserWindow({
    width: 800, 
    height: 600, 
    icon: path.join(__dirname, 'icon.ico')
  })

  win.maximize();

  win.loadURL('https://stackoverflow.com/', {"extraHeaders" : "pragma: no-cache\n"});

  win.on('closed', () => {
    win = null
  })
}

app.on('ready', createWindow)

app.on('browser-window-created',function(e,window) {
    window.setMenu(null);
});

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  if (win === null) {
    createWindow()
  }
})

package.json

包.json

{
  "name": "test",
  "version": "1.0.0",
  "main": "main.js",
  "build": {
    "appId": "com.test.app",
    "copyright": "test",
    "productName": "test"
  },
  "devDependencies": {
    "electron": "1.7.9",
    "electron-builder": "^19.46.4",
    "electron-packager": "^10.1.0"
  }
}

with electron-packageri have builded the package to release:

使用电子打包器,我构建了要发布的包:

electron-packager . --overwrite --asar=true --platform=win32 --arch=ia32 --prune=true --out=release-builds

the total size of the builded package is 107 MB.

构建包的总大小为107 MB

Anyone have tips to reduce the size of the package?

有人有减小包装尺寸的提示吗?

回答by Bharathvaj Ganesan

You can reduce the electron app size by packaging using electron-builderpackage.

您可以通过使用电子生成器包进行打包来减小电子应用程序的大小。

PicArtis an electronjsapp which I developed recently. It is built using reactJS. Initially when I packaged the app using electron-packager the Window's build size was around 98 MB. Then I found this awesome boilerplate electron-reactwhere they configured the electron-builder to produced optimised build size. After using those configuration setup, PicArt's build is now around 36 MB.

PicArt是我最近开发的一个电子应用程序。它是使用reactJS 构建的。最初,当我使用电子打包器打包应用程序时,Window 的构建大小约为98 MB。然后我发现了这个很棒的样板电子反应,他们配置了电子构建器以生成优化的构建尺寸。使用这些配置设置后,PicArt 的构建现在约为36 MB

Yes, it is possible to reduce the app size , but it quite painful and time consuming to configure the build setup.

是的,可以减少应用程序的大小,但是配置构建设置非常痛苦和耗时。

回答by Sodj

I managed to reduce the final size of my mac app from 250MBto 128MBby moving 'electron' and my reactJs dependenciesto devDependenciesin package.json... since all I need is going to be in the final bundle.js

我设法通过将“电子”和我的 reactJs 移动到in将我的 mac 应用程序的最终大小从250MB 减少128MB......因为我需要的只是最终的 bundle.jsdependenciesdevDependenciespackage.json

But sadly I couldn't get it any lower than that because the electron framework is 118MBwhich is something if you're making a small app, but I guess that's the price to pay for making cross-platform web apps

但遗憾的是,我无法得到比这更低的值,因为电子框架是118MB,如果您正在制作一个小型应用程序,这已经足够了,但我想这是制作跨平台 Web 应用程序的代价