miracle2k / webassets

Asset management for Python web development.
BSD 2-Clause "Simplified" License
923 stars 259 forks source link

RequireJS exclude support #417

Open lnielsen opened 9 years ago

lnielsen commented 9 years ago

We have added support to the RequireJSFilter for being able to exclude files from other bundles (using the --exlude option to r.js). Would that be something you'd be interested in integrating it into webasset? If so I'll open a PR.

When building multi-page apps using RequireJS, it's useful to have core dependencies packed into one file, and per-page decencies into a separate files. Take e.g.:

# js/core.js
require(["jquery"], function($) { ... })
# js/page.js
require(["jquery", "coollib"], function($, coollib) {...})

With the bundles:

core = Bundle(
    'js/core.js',
    filters='requirejs',
    output='gen/core.packed.js'
)

page = Bundle(
    'js/page.js',
    filters='requirejs',
    output='gen/page.packed.js'   
)

What will happen currently is that core.packed.js contains all of jquery, however gen/page.packed.js also contains all of jQuery.

We suggest adding an exclude option to RequireJSFilter so that you co do something like:

core = Bundle(...)

page = Bundle(
    'js/page.js',
    filters=RequireJSFilter(exclude=[core]),
    output='gen/page.packed.js'   
)

This will ensure that r.js received the --exclude argument with a list of files from the excluded bundles, and that in above example jquery will not be packed into the page bundle.

miracle2k commented 9 years ago

I'm not familiar with the RequireJS filter myself, but sure, that sounds useful.