I've recently started trying to make a desktop application using Electron and got Jquery working in the app.
I installed the following packages with NPM install package -save
Node package dependencies:
"electron-prebuilt": "^0.36.0",
"jquery": "^2.1.4",
"jquery-ui": "^1.10.5"
And I'm using the following code to run Jquery and Jquery Ui
window.$ = window.jQuery = require('jQuery');
require("jquery-ui");
problem: Jquery is loaded across the app, but UI
isn't.
HTML EG:
<div id="bod">
text
</div>
<script>
$( "#bod" ).click(function(){
var div = $("<div></div>").load("./html/testDialogue.html" );
console.log( div );// jquery works like expected
$(this).dialog();// UI not apart of JQuery extensions.. or loaded at all
});
</script>
For anyone else like me who came across this trying to globally load jQueryUI into your electron app - the best way to do this is not to install the jquery-ui NPM package, but to download the minified jQueryUI script from the CDN, store it locally in a resource folder and include it in your index directly below the line declaring your global jQuery variable and above the renderers you want to use it in, like so:
This will give access to all jQueryUI functions via the global jQuery variable within your render scripts.
If you want your libraries as Globals and not as AMD modules you can install the dependencies with bower and add the scripts to your index.html file as you would in a regular web site. In the case of Jquery you would still need to require it and declare the globals because Jquery detects in which context is running.
But for JqueryUI I would recommend installing it as global. Is possible that JqueryUI is also detecting the context. If that's the case it should infer there are no Global variable to be attached on. Here they say how to use it as an AMD module.
https://learn.jquery.com/jquery-ui/environments/amd/
In case jQuery-UI dialog import that module by:
import 'jquery-ui/ui/widgets/dialog';
The jquery-ui package is specifically made to be built after the installation.
Try the jquery-ui-dist package instead:
npm i jquery-ui-dist
Then you can just require it like this: