kriswallsmith/assetic — Issue #150: Support for generic build steps
Author: kmontag
Created: 2011-11-05 01:35:02+00:00
State: open

Starting with an example: I have a project that uses Compass to build the stylesheets. It's of course possible to use the Compass filter for compilation, but this comes with a few issues - for example, I must manually clear the cache when a Sass dependency is changed (I know asset dependencies are on the way), and I must rely on the Assetic filter to configure the build, rather than standard Compass configuration via a config.rb file. More abstractly, it's difficult to use the "standard" Compass workflow of watching a directory for changes, passing in debugging args when I want to (e.g. --trace), and showing compilation errors as they pop up. Compass is really built to deal with collections of files as a project, whereas Assetic is concerned with the content of individual assets, and there's a disconnect there in workflow.

What I'd like to be able to do is seamlessly use "standard" Compass to build a collection of Sass files (in a single build step), and then process the generated CSS files with Assetic. I'm imagining (roughly) something like:

{% stylesheets build='compass' filter='?yui_css' '/path/to/built/stylesheets/*.css' %}
...
{% endstylesheets %}

where the 'build' option means to run 'compass compile' in a configured folder once, before processing any of the stylesheets as assets. This leverages Compass' built-in caching, makes filemtime work as a test for the Assetic asset cache, and allows for a more flexible development workflow.

The concept of preemptive build steps seems generically applicable (for example, in conjunction with RequireJS) for tools that deal with builds of more than one file at a time, require configuration that's difficult to map to PHP or to the content of a single asset, or have richer development workflows than just compilation. Though I'm not sure if this should be within Assetic's scope - of course it's also always possible to just commit built files to a repository, or execute a build before dumping assets in deployment.