本文介绍了电子封装:减小封装尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个简单的应用:

I made a simple Electron app:

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()
  }
})

软件包。 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-packager i have builded the package to release:

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

已构建软件包的总大小为 107 MB

the total size of the builded package is 107 MB.

任何人都可以找到减小软件包大小的技巧。

Anyone have tips to reduce the size of the package?

推荐答案

您可以使用软件包。

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

PicArt is an electronjs app 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-react where they configured the electron-builder to produced optimised build size. After using those configuration setup, PicArt's build is now around 36 MB.

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

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

这篇关于电子封装:减小封装尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:44