Configuration issue when creating a standalone module

107 views
Skip to first unread message

Guido Spaanbroek

unread,
May 18, 2013, 12:37:49 PM5/18/13
to django-...@googlegroups.com
Hi Dave,

Great project, I like it! I've managed to get Django-require working and am really impressed how it works; it is really powerful.
The only struggle I have is to get Almond.js working and I hope you can point me in the right direction. My aim is to have one resulting Javascript file called xilongo.js that contains all my modules and dependencies.

When I perform a collectstatic the program tries to retrieve the modules from the wrong directory when I define REQUIRE_STANDALONE_MODULES:

Error: ENOENT, no such file or directory '/xilongocms/js/lib/page_load.js'

How can I change the configuration in such a way that it looks for page_load.js in the js directory and not in the js/lib directory? I've been struggling for quite a while now but so far I have not been able to find the right answer.

These are the relevant settings in settings.py:

REQUIRE_BASE_URL = "xilongocms/js/lib"

REQUIRE_STANDALONE_MODULES = {
    "../xilongo_loader": {
        # Where to output the built module, relative to REQUIRE_BASE_URL.
        "out": "../xilongo.js",
    },
}

This is my directory structure:
- static\xilongocms directory with modules
 - xilongo_loader.js
 - page_load.js
 - xvisuals.js
 - xplayer.js
 - …etc.
 - static\xilongocms\lib directory with depend libs
 - jquery.js
 - require.js
 - almond.js
 - r.js
 - etc.

And this is my xilongo_loader.js:
requirejs.config({
    //By default load any module IDs from js/lib
    baseUrl: '/static/xilongocms/js/lib',
    paths: {
        ajax_menu: '../ajax_menu',
        background: '../background',
        orientation: '../orientation',
        page_load: '../page_load',
        xplayer: '../xplayer',
        xvisual: '../xvisual'
    }
});

require(["jquery", "page_load"],
function($, page_load) {
    page_load.load(post_page_load);
});

... other modules will be loaded in post_page_load

Hope you can help me out,

Best regards,

Guido

Dave Hall

unread,
May 18, 2013, 2:04:38 PM5/18/13
to Guido Spaanbroek, django-...@googlegroups.com

Hi,

This is more of a requirejs problem than a django-require one, but I'll do my best!

Basically, I'd suggest making your base URL the root of your JS structure, and making your main module live in the top level of the base URL. If this means using the paths config to fix a few paths, then that's okay.

In my experience, placing main modules anywhere but the root of the base URL is a bit of a pain with requirejs.

--
You received this message because you are subscribed to the Google Groups "django-require discussion and announcements" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-requir...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Message has been deleted

Guido Spaanbroek

unread,
May 19, 2013, 8:15:54 AM5/19/13
to django-...@googlegroups.com
Hi,

Thank you, that helped me out. I've got it now all working including Almond.

I moved the REQUIRE_BASE_URL to "xilongocms/js" which gave me initially a problem but that was solved by adding

paths: {
    …
        jquery: 'lib/jquery'
}

to requirejs.config. Way I do not have to do for any other of the resources in lib is a mystery to me but that is indeed a requirejs issue.

Anyway, thanks again,

Best regards,

Guido

Dave Hall

unread,
May 19, 2013, 2:17:21 PM5/19/13
to Guido Spaanbroek, django-...@googlegroups.com

The jquery issue was caused by the jQuery codebase declaring that the jQuery module is called "jquery", and not "lib/jquery". That is, unlike most AMD modules, it names itself explicitly rather than implicitly.

You can get around this by setting a paths config for jquery.

On 19 May 2013 11:55, "Guido Spaanbroek" <guid...@gmail.com> wrote:
Hi,

Thank you, that helped me out. I've got it now all working including Almond.

I moved the REQUIRE_BASE_URL to "xilongocms/js" which gave me initially a problem.

In page_load.js, the first module loaded after the main (xilongo_loader.js) resulted in a Javascript error:

define(['lib/jquery'], function($) {

    $ remains for some reason undefined. Hoewever, jquery.js is loaded in the DOM.
});

So I moved jquery.js to the REQUIRE_BASE_URL and that solved the problem. This issue did not occur with any of the other javascript resources in the lib folder like jplayer.js and some UI stuff.

Why I can not have jquery.js in the lib folder remains a mystery to me. The last time I changed  REQUIRE_BASE_URL to the js/lib folder to get that working but that obviously was not the solution. In the requirejs documentation I do not find an explanation either; it covers retrieving jquery.js from a CDN or making use of a jquery-require packages but I miss a straightforward example with jquery. Of course this is indeed a requirejs issue and not related to django-require.

Anyway, thanks again,
Reply all
Reply to author
Forward
0 new messages