将HTML项目打包成exe应用

搭建环境

1、安装Node.js1

2、全局安装cnpm2(执行控制台命令:npm install -g cnpm --registry=https://registry.npm.taobao.org);

3、全局安装electron3(执行控制台命令:cnpm install -g electron);

4、全局安装打包器(执行控制台命令:cnpm install electron-packager -g)。

创建项目

1、将electron的项目模板克隆到本地(执行git命令:git clone https://github.com/electron/electron-quick-start);

2、安装依赖(进入项目文件夹,执行控制台命令:cnpm install);

3、将您的项目文件复制到electron的项目模板文件夹内。在项目目录下有一个main.js文件,可修改createWindow函数自定义我们的应用程序:

function createWindow () {
  // Create the browser window.
  mainWindow = new BrowserWindow({
    fullscreen: true,// 全屏
    // width: 800,
    // height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })

  mainWindow.setMenu(null);// 隐藏菜单

  // and load the index.html of the app.
  mainWindow.loadFile('index.html')// 设置主窗口对应的HTML文件

  // Open the DevTools.
  // mainWindow.webContents.openDevTools()

  // Emitted when the window is closed.
  mainWindow.on('closed', function () {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null
  })
}

打包

进入项目文件夹,执行控制台命令:electron-packager . 文件名 --win --out 文件夹名 --arch= ia32/x64/armv7l/arm64/mips64el --version版本号 --overwrite --ignore=node_modules --icon=图标.ico


  1. https://nodejs.org/en/ ↩︎

  2. npm是JavaScript的包管理器,cnpm是npm的淘宝镜像,访问速度快 ↩︎

  3. 用HTML、CSS、JavaScript来构建跨平台桌面应用程序的一个开源库 ↩︎

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值