leapmotion/leapjs

Optimization issues with r.js

majodev opened this issue · 1 comments

Hi!

I'm running into troubles optimizing leap.min.js with r.js and I'm not quite sure if it's a problem with leapjs or requirejs. Everything runs fine during development until I build a minified version.

I've opened an issue and uploaded an example to try out. Hopefully you can help me to resolve my problem. :)

James Burke was so kind to resolve my problems with leap.js when optimized via r.js. Overall the problem is related to your approach to use browserify for converting the node leap-package. Here's a working require.js config covering leap.js that can be optimized via r.js. The important part that is needed in order for it to work is onBuildRead.

var config = {
  baseUrl: "src/",
  paths: {
    "Leap": "../node_modules/leapjs/leap"
  },
  optimize: "none",
  onBuildRead: function(id, url, contents) {
    if (id === 'Leap') {
        return 'define(\'Leap\', [], function() {var define;\n ' + contents + ' return Leap; });';
    } else {
        return contents;
    }
  },
  logLevel: 0,
  name: "issue", // Name of script to start building from
  insertRequire: ["issue"],
  out: 'build/' + pjson.name + '-' + pjson.version + '.min.js' // Where to output
}; 

More information can be found here.