purescript-jquery icon indicating copy to clipboard operation
purescript-jquery copied to clipboard

Use browserify to "require" jQuery?

Open anttih opened this issue 9 years ago • 1 comments

The FFI code relies on the jQuery global var which makes it difficult to bundle all the deps with browserify. If one of your dependencies has require('jquery') in there and you use browserify to bundle those deps, you will end up with two jquerys on the page: one included with a script tag (to have jQuery available as a global) and one in the bundle. There may be hacks to get around this (setting jQuery as global somewhere at the top level), but I wouldn't want to do that. I think this day and age, one should bundle all the deps anyway.

So, what I suggest is we add var jQuery = require('jquery') in the FFI code.

anttih avatar Jul 10 '15 05:07 anttih

One workaround is to add the jQuery require in whichever application relies on jQuery. For example:

Main.ps

foreign import jQuery :: Foreign

...

Main.js

"use strict";

var jQuery = require('jquery');
window.jQuery = jQuery;
exports.jQuery = jQuery;

colehaus avatar Dec 13 '18 22:12 colehaus