Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly require jquery UI in nodejs

I'm developing a node library that depends on jQuery and jqueryUI. I use browserify to make it accessible to a browser page.
So in my library code, there can be for example such kind of code:

var createMenu = function (target, options) {
  $target = $(target);
  $target.menu(options);
}

I require jQuery and jQueryUI like this:

var $ = jQuery = require("./node_modules/jquery");
require("./node_modules/jquery-ui-dist");

but when I call createMenu function in the browser, it logs TypeError: $target.menu is not a function.

JQueryUI doesn't seem to be properly loaded but I didn't find documentation on how to load it properly.

I also tried $.ui = require('./node_modules/jquery-ui/ui/widget.js') without any more luck.

If I do the following:

jQueryUI = require("./node_modules/jquery-ui")
console.log(jQueryUI)

it only logs an empty object.

Any idea on the proper way to log jQueryUI to use it in nodejs?

like image 575
chateau Avatar asked Nov 08 '22 08:11

chateau


1 Answers

These steps should work:

Install these packages from npm

npm install jquery
npm install jquery-ui-dist

Import them in HTML file, like

<script src="/node_modules/jquery/dist/jquery.min.js"></script>
<script src="/node_modules/jquery-ui-dist/jquery-ui.min.js"></script>
like image 176
brijesh-pant Avatar answered Nov 14 '22 23:11

brijesh-pant