加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何将现有的角应用程序移植到电子?

发布时间:2020-12-17 09:57:26 所属栏目:安全 来源:网络整理
导读:我是一个有角度的初学者和一个完整的电子菜鸟.我想知道是否可以通过使用webapp的大部分现有代码库将现有的角度应用程序移植到电子? 我在这上面找到了几个链接,但在Google上并没有太多.大多数结果都谈到从角度和电子开始创建一个桌面应用程序 – 这是我的意
我是一个有角度的初学者和一个完整的电子菜鸟.我想知道是否可以通过使用webapp的大部分现有代码库将现有的角度应用程序移植到电子?

我在这上面找到了几个链接,但在Google上并没有太多.大多数结果都谈到从角度和电子开始创建一个桌面应用程序 – 这是我的意图,但我想使用我现有的大部分代码库,理想情况下只需添加webpack和电子相关的配置来编译现有代码库中的electon应用程序不想维护相同代码库的两个版本.

我可以使用这个桥来访问Electron API(虽然我不知道它将如何挂在一起)
https://github.com/develephant/ngElectron

人们通常做什么?

以下是我将Electron添加到现有AngularJS应用程序的步骤.
1.克隆现有的Angular app git clone https://github.com/angular/angular-seed.git.
2. cd angular-seed.
3. npm install – 保存电子.
4.在/ app中,创建一个main.js文件并粘贴:
const electron = require('electron')
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow

// 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 mainWindow

function createWindow () {
  // Create the browser window.
  mainWindow = new BrowserWindow({width: 800,height: 600})

  // and load the index.html of the app.
  mainWindow.loadURL(`file://${__dirname}/index.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
  })
}

// 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',function () {
  // On OS X 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',function () {
  // On OS X 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 (mainWindow === 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.

>在/ app中,创建一个空白的renderer.js文件.>在package.json的根目录中添加“main”:“main.js”.>在package.json的“scripts”部分中,将“start”更改为“start”:“electron.”.> npm install&& npm开始.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读