javascriptrequirejsglobal-namespace

glMatrix 2.2.0 with RequireJS


All definitions of glMatrix 2.2.0 seem to be undefined when included with RequireJS. However, on page inspection, it is being included in the HTML as a script tag.

However the same setup does work with glMatrix 1.3.7.

The require configuration is as follows:

require.config({
baseUrl: 'js/app',
paths: {
    jquery: '../lib/jquery',
    glm: '../lib/gl-matrix'
}
});

require(['main']);

And main.js looks like (jquery works in this instance):

define(function (require) {
var $ = require('jquery');
require('glm');

$(function () {
    var a = mat4.create();
    $('body').html("hello: " + a);
});
});

I also have the same problem with other global-namespace libraries like stats.js.

Although defining the scripts in HTML works, I would preferably like it to work with RequireJS for minimisation/concatenation.

<script src="js/lib/stats.js"></script>
<script src="js/lib/gl-matrix-min.js"></script>

Hopefully I'm missing something obvious with this one, as I'm tearing my hair.

Thanks in advance for any suggestions.


Solution

  • I use glmatrix too with require.js, the most recent version has require.js support and for me it seems to work fine.

    I have however I slightly different usage with require.js, my modules usually start like this:

    define(['lib/glmatrix/gl-matrix'],
        function(glmatrix) {
            var myModule = function() {};
            // use glmatrix.vec3, etc here
            return myModule;
    });
    

    Does this work for you?