美文网首页
antDesignPro + electron 实现桌面安装运行

antDesignPro + electron 实现桌面安装运行

作者: 我想freestyle | 来源:发表于2021-08-30 10:52 被阅读0次

简单的分享下自己实现的过程

  1. 首先创建一个 ant-design-pro 项目
    2.安装electron (npm install electron)
    3.在根目录创建一个main.js
const {
  app,
  BrowserWindow
} = require('electron')
const path = require('path')
const url = require('url')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win

function createWindow() {
  // Create the browser window.
  win = new BrowserWindow({
    width: 1920,
    height: 1080,
    webPreferences: {
      webSecurity: false
    }
  })
  // 生产环境
  win.loadURL(path.join('file://', __dirname, 'build/index.html'))
  // 本地环境
  // win.loadURL('http://localhost:8001/');

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

  // Emitted when the window is closed.
  win.on('closed', () => {
    // 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.
    win = null
  })
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', () => {
  // On macOS it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  // On macOS it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (win === null) {
    createWindow()
  }
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

4.打开package.json文件,添加 'main' 以及 'electron-start'

  "name": "ant-design-pro",
  "main": "main.js",
  "scripts": {
   "electron-start": "electron ."  
}

5.在config配置(重点)

publicPath: './',
 history: {
    type: 'hash',
  },
outputPath: 'build',
  1. 把main.js放到public文件夹下,因为webpack打包时public文件夹下的文件都会原封不动地复制到build文件夹中。

7.执行启动命令 (本地启动 antdesign项目跑起来 在mian.js 里面win.loadURL('http://localhost:8001/')地址改成你项目运行的地址
生产地址注释掉,切记打包生产的时候要改回来)
)

npm run electron-start

6.安装electron打包工具 electron-packager

npm run electron-packager
"scripts": {
  "packager": "electron-packager . fukaiitapp --out fukaiitapp --arch=x64 --overwrite --asar --ignore=node_modules",
}

7.执行打包命令 (执行命令之前先把项目打一个最新的生产包)

npm run packager

会生成一个 fukaiitapp文件夹 然后进去会看到如下图(双击运行)


1630289042(1).jpg

8.在通过 Inno Setup 生成安装包 (自行百度步骤)

相关文章

网友评论

      本文标题:antDesignPro + electron 实现桌面安装运行

      本文链接:https://www.haomeiwen.com/subject/somniltx.html