Angularjs 如何将现有angular应用程序移植到electron?
我是一个角度的初学者和一个完全的noob电子。我想知道是否可以使用webapp的大部分现有代码库将现有angular应用程序移植到electron 我在这上面找到了几个链接,但在谷歌上没有找到多少。大多数结果都是从angular和electron开始创建桌面应用程序-这是我的意图,但我想使用我现有的大部分代码库,理想情况下,只添加webpack和electron相关配置,从现有代码库编译electron应用程序,因为我不想维护同一代码库的两个版本 我可以使用这个桥来访问Electron API(尽管我不确定它将如何结合在一起)Angularjs 如何将现有angular应用程序移植到electron?,angularjs,electron,Angularjs,Electron,我是一个角度的初学者和一个完全的noob电子。我想知道是否可以使用webapp的大部分现有代码库将现有angular应用程序移植到electron 我在这上面找到了几个链接,但在谷歌上没有找到多少。大多数结果都是从angular和electron开始创建桌面应用程序-这是我的意图,但我想使用我现有的大部分代码库,理想情况下,只添加webpack和electron相关配置,从现有代码库编译electron应用程序,因为我不想维护同一代码库的两个版本 我可以使用这个桥来访问Electron API(
人们通常做什么?以下是我在现有AngularJS应用程序中添加Electron的步骤。
1.克隆现有Angular app
git克隆https://github.com/angular/angular-seed.git
2. <代码>cd角形种子
3. <代码>npm安装--保存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.
“main”:“main.js”
“start”:“electron”。
npm安装和&npm启动
加载URL路径应为dist folder index.html,请正确检查文件夹路径,否则应用程序将加载空
mainWindow.loadURL('dist/index.html')
你有没有想过?我也对它感兴趣。我得到了错误!“无法在c:/PROJECT\u文件夹中找到Electron应用程序无法找到模块c:/PROJECT\u文件夹”。在我的情况下,它也可以在不添加renderer.js file.sry的情况下工作。可能我遗漏了什么。与“现有应用程序”的连接在哪里?angular seed是GitHub上的现有应用程序。这个过程将从它创建一个电子应用程序。当我将#6更改为“main”时,它为我工作:“app/main.js”