Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using leapjs with bower and require - undefined? #121

Open
saschagehlich opened this issue Nov 27, 2013 · 8 comments
Open

Using leapjs with bower and require - undefined? #121

saschagehlich opened this issue Nov 27, 2013 · 8 comments

Comments

@saschagehlich
Copy link
Contributor

Hey there,

I'm using leapjs via bower and using requirejs, but when I do a require("leapjs");, it returns undefined. Does leapjs support requirejs?

Best,
Sascha

@bingomanatee
Copy link
Contributor

No. LeapJS is not currently designed to be compatible with requirejs. We may make it so in the future but at this point, Leap, the namespace that LeapJS creates, is a global, and is not designed to work with requirejs.

@bingomanatee
Copy link
Contributor

We welcome any community involvement that brings Leap into the requirejs tent. Send us a pull request and we will look at it.

@mcfarljw
Copy link

I'm interested in having this functionality too. I'm actually ok with it just loading in the global namespace. The problem I'm having now is it doesn't play friendly with the requirejs optimizer when concatenating into a single file (with and without minification).

I'll give it a look and see if I can find any quick and easy fixes to get it working, but definitely think it's something that should be supported in the future.

@pehrlich
Copy link
Contributor

Okay, we'll keep this in mind. I'm not too familiar with RequireJS --yet-- so I'd be interested to hear how you're using it and see what's involved in integration. (also, RequireJS vs CommonJS..?)

@mcfarljw
Copy link

Hey @pehrlich, my application is using requirejs in two ways. The actual application files I've coded up are being loaded in a modular way, but I'm using it to load all of my libraries up front (in a not so modular way). Here is a link to the libraries file I'm using:

https://github.com/mcfarljw/skritter-html5/blob/13c261c37c2cce750bc6fe872b98aa7f9d574cbf/public_html/js/app/Libraries.js

So in my instance I'm not too sure if it's not playing nicely with requirejs or it's not happy about being concatenated in with the other specified libraries. I'm be inclined to say the latter, because it loads globally and works just fine when not concatenated.

@bingomanatee
Copy link
Contributor

FWIW if you load the Leap.js library before you load require, you can refer to it as a global -- that is if you set your script includes in the right order leap can be engaged from Require even though it is not itself AMD/require friendly.

@dubbl
Copy link

dubbl commented Jul 21, 2014

You can use require.js and LeapJS without globals if you define a shim in the requireJS config and export 'Leap', like

require.config({
    paths: {
        leapjs: 'libs/leap-0.6.0'
    },
    shim : {
        'leapjs': { exports: 'Leap'}
    }
});
// load leap motion library
require(['leapjs'], function(Leap) {
    console.log(Leap);
});

Edit: Same thing, now with LeapJS plugin support:

require.config({
    paths: {
        leapjs: 'libs/leap-0.6.0',
        leapjswithplugins: 'libs/leap-plugins-0.1.6'
    },
    shim : {
        'leapjs': { exports: 'Leap'},
        'leapjswithplugins': {exports: 'Leap', deps: ['leapjs']}
    }
});
// load leap motion libraries
require(['leapjswithplugins'], function(Leap) {
    console.log(Leap);
    }).use('screenPosition'); // for example
});

@pehrlich
Copy link
Contributor

What do you guys think of adding in a shim to the library itself, like this?

https://github.com/leapmotion/leapjs-plugins/blob/master/utils/leap-plugins-0.1.7-utils.js#L2-L12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants