How to add JQuery to Electron? [duplicate]

2

I'm a web developer, I've tried methodologies in an English post, but ... none works, I want to add JQuery to electon .

I've used this without window.$ does not work.

<script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>

I tried with window.$ working but stopped working for some unknown reason ...

<script src='https://code.jquery.com/jquery-3.2.1.min.js' onclick='window.$ = window.jQuery = module.exports;'></script>

Does anyone know any script to make JQuery work?

I want to leave it in my main.js (index.js) instead of leaving it on a webpage if possible. If it does not, I'll leave it on the same webpage.

    
asked by anonymous 01.12.2017 / 05:13

1 answer

3

You need to use node to install jQuery so you can use it on server-side.

See below:

npm install jQuery

Then you just have to include the jQuery package (like suggested by Anderson Carlos Woss):

var $ = require('jQuery');

In the example illustration below, I include the package in the index.html file, however, you can include it in your main.js or in a separate window.

<script>
    // You can also require other files to run in this process
    require('./renderer.js')
    var $ = require('jQuery');

    // Pode usar o jQuery normalmente agora.
    $(document).ready(
        function() 
        { 
            $("<h1>Test jQuery</h1>").appendTo('body');
        }
    );
</script>
    
06.02.2018 / 05:27