Using RequireJS with Django

336 views
Skip to first unread message

jpk

unread,
Feb 28, 2012, 2:11:32 AM2/28/12
to django...@googlegroups.com
Hi django-users,

I'm working on a django project with a quickly growing javascript
front-end using backbone. The backbone application has grown to the
point where it needs to be split into modules across multiple files.
I'm looking into RequireJS to do that.

I've done some research on how to best use require in django, but
haven't found much. My first stab at this is probably going to be
more or less: Take the single javascript file I have now, break it
into AMD modules in a sub-directory of the static directory the single
file is in, set up require's minification stuff to put the minified
javascript there in another sub-directory the same static directory,
then set up templates to conditionally include the source/minified
javascript for development/production. Then I'll figure out some
mechanism to run the minification stuff on the server during
deployment.

So, what I'm looking for is wisdom related to carrying out that
process and maintaining it. Has anyone set up require in a django
project before, and have any tips to share? I'd love to hear them!

Thanks
john

--
john p. kiffmeyer

ojo

unread,
Feb 28, 2012, 4:15:22 PM2/28/12
to Django users
On Feb 28, 8:11 am, jpk <j...@thekiffmeyer.org> wrote:
> I'm working on a django project with a quickly growing javascript
> front-end using backbone.  The backbone application has grown to the
> point where it needs to be split into modules across multiple files.
> I'm looking into RequireJS to do that.

> So, what I'm looking for is wisdom related to carrying out that
> process and maintaining it.  Has anyone set up require in a django
> project before, and have any tips to share?  I'd love to hear them!
>

You may want to take a look at JqResources: https://github.com/ojo/django-jqresources

--
Regards
Aleksander Zdyb

David Hall

unread,
Nov 1, 2012, 3:11:02 PM11/1/12
to django...@googlegroups.com
I realise that this is an old topic, but I hope this is useful to other people looking to use RequireJS with Django.

You should take a look at django-require, which takes care of integrating the r.js optimizer with Django. I've just pushed up the 1.0.0 release.


It optimises your project using r.js in a post_process step. There's two built-in storage classes, and a mixin that can integrate with any other django storage backend (for example, S3BotoStorage from django-storages).

It also supports compiling standalone modules using almond.js.

It's a new package, so all feedback gratefully received!
Reply all
Reply to author
Forward
0 new messages