Why asset converters cannot work with asset source path?

interface AssetConverterInterface



     * Converts a given asset file into a CSS or JS file.

     * @param string $asset the asset file path, relative to $basePath

     * @param string $basePath the directory the $asset is relative to.

     * @return string the converted asset file path, relative to $basePath.


    public function convert($asset, $basePath);


For example, I use less for my styles. And I need to convert them to css.

Current implementation forces me to copy less sources to assets directory and convert them, after that.

The directory is published based on its timestamp.

So if my less file is changed, directory timestamp is not changed and I need to delete assets or set forceCopy to true in AssetManager in order to see my changes.

In production it is not a problem to delete assets after update. But in development it is not possible to change less file, press "refresh" is the browser and see the results.

I propose to pass one more parameter to this function with AssetBundle object. It will allow to immplement any logic on converter side. In current architecture is is not possible, because convert() is called from AssetBundle, which cannot be overrided for all bundles at once.

What’s the problem with that?

It is very slow. It requires building of all assets, even if they are not changed. I’m not even saying about copying.

On my machine and project it takes approximately 15 sec/request. It is not very critical, but slows down the development.

Ofcourse, SSD, more memory, more CPU, tuned environment can solve a problem at least partially, but not always affordable.

15 sec/request is way too long, indeed. Before switched to Grunt I have used the forceCopy => true setting (in the development environment, of course) and it never took noticeable amount of time to publish assets on an absolutely average PC. Maybe your application requires much more asset processing than mine did.

Using an external tool like Grunt (which - as you would expect from a dedicated build tool - is much more configurable/customizable than AssetManager) or an IDE plugin for less compilation and skipping asset publishing by working directly in a web-accessible directory isn’t an option for you? Yii’s asset publishing is more suited for reusable extensions than applications.

It is an option in some extent. But some files are in those "reusable extensions" and it would be nice not to completely destroy and idea of assets.