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
Comments
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. |
We welcome any community involvement that brings Leap into the requirejs tent. Send us a pull request and we will look at it. |
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. |
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..?) |
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: 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. |
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. |
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
}); |
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 |
Hey there,
I'm using leapjs via bower and using requirejs, but when I do a
require("leapjs");
, it returnsundefined
. Does leapjs support requirejs?Best,
Sascha
The text was updated successfully, but these errors were encountered: