如何将现有的angular应用程序移植到electron?

xzlaal3s  于 2024-01-04  发布在  Electron
关注(0)|答案(2)|浏览(175)

我是一个angular的初学者,也是一个完全的electron的新手。我想知道是否有可能通过使用web应用程序的大部分现有代码库来将现有的angular应用程序移植到electron上?
我在Google上找到了一些关于这个的链接,但没有太多。大多数结果都是从angular和electron开始创建一个桌面应用程序-这是我的意图,但我想使用我现有的大部分代码库,理想情况下只添加webpack和electron相关的配置来从现有的代码库编译electon应用程序,因为我不想维护同一代码库的两个版本。
我可以使用这个桥来访问Electron API(尽管我不确定它将如何连接在一起)https://github.com/develephant/ngElectron
人们通常做什么?

yh2wf1be

yh2wf1be1#

以下是我将Electron添加到现有AngularJS应用程序中所采取的步骤。
1.克隆一个现有的Angular应用程序git clone https://github.com/angular/angular-seed.git
2. cd angular-seed的值。“
3. npm install --save electron的值。该值为
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.

字符串
1.在/app中,创建一个空白renderer.js文件。
1.在package.json的根目录中添加"main": "main.js"
1.在package.json的“脚本”部分中,将“启动”更改为"start": "electron ."

  1. npm install && npm start的值。“
eqfvzcg8

eqfvzcg82#

loadURL路径应该是dist文件夹index.html,请检查您的文件夹路径正确,其他明智的应用程序将加载空

mainWindow.loadURL('dist/index.html')

字符串

相关问题