我正在尝试使用电子将网页捆绑到应用程序中 .

我可以使用示例应用程序,但我的网页使用jquery和依赖于jquery的各种库来运行 . 就其本身而言,该网站在网络浏览器中运行良好,但是当通过电子启动它时,我从库的define / export语句开始出现各种javascript错误 .

我的电子应用程序结构如下:

main.js
package.json
app
  index.html
  js/app.js
  js/lib/jquery.js
  js/lib/library1.js
  ...

其中app包含依赖于所包含的库的所有自定义代码,索引如下所示:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>[TITLE]</title>
    <link rel="stylesheet" href="css/main.css">
</head>

<body>
<script src="js/lib/jquery.js"></script>
<script src="js/lib/library1.js"></script>
<script src="js/app.js"></script>
</body>
</html>

Package.json看起来像这样:

{
  "name"    : "LosYork",
  "version" : "0.1.0",
  "main"    : "main.js"
}

和main.js是电子文件,它只是复制代码from the quickstart

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 + '/app/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/index.html) .

我知道我并没有完全掌握使用节点的"require"的过程,我在快速入门中看到index file中发生了一个require语句,以及the bottom of main.js中的代码注释说这里也需要一些东西 . ,但如果我尝试将脚本包含为require语句而不仅仅是as等,我注意到没有区别 .

我将从依赖于jquery的库中看到的典型错误是,例如:

jQuery is not defined

在行中:

(function(factory) {
    'use strict';
    if (typeof define === 'function' && define.amd) {
        define(['jquery'], factory);
    } else if (typeof exports !== 'undefined') {
        module.exports = factory(require('jquery'));
    } else {
        factory(jQuery); //ERROR OCCURS HERE
    }

}(function($) {
  ...
}));

如何将这些库包含在电子中,以便它们在应用程序中彼此可用,就像在我的普通Web应用程序中一样?