DarthFubuMVC/fubumvc — pull request #259 by bobpace (2012-03-27 01:03:59+00:00)
Title: Asset precompilers

I needed a way to get my hands on the fully built asset pipeline before it got baked into the container.

If you register an IAssetPrecompiler as a service, it will get picked up by the AssetPrecompilerActivator and registered with the AssetGraph so that later right before the AssetGraphConfigurationActivator calls "CompileDependencies" on the asset graph it calls for all the precompile actions that have been registered to get run, giving you an opportunity to inspect the built IAssetPipeline and use the IAssetRegistration interface to make additional calls on it before its registered with the container.

I am using this new functionality to inspect all .js files to see if they are written in the requirejs format of either require or define modules and if so, register all their dependencies with the asset pipeline so later when we ask for file1.js and it has requirejs dependencies it will know to bring them down for us.

example:

file1.js
define(['utility'], function(utility) {
});

utility.js
define(function() {
})

calling this.Asset("file1.js") will know to already bring down its dependency of utility.js for you without you needing to specify it somewhere in a script.config.

The RequireJsAssetPrecompiler is my first use of IAssetPrecompiler but I will be placing that in a separate repository once this pull request goes in so I can use it.

Let me know if you have any questions/feedback/suggestions about the intended usage.