Source assets and publishing

I’m trying to think of a workflow of optimizing and publishing site assets (css, js, img), with a little help of the Yii 2 Asset Manager.

Normally, for asset optimisation (in non-Yii sites), I use the following:

  • LESS files, with a .less-file watcher in PhpStorm, which generates a single CSS compressed file via Node Less Compiler.

  • JS: I have a Phing task (in PhpStorm), which (manually) builds a single JS file via concat and YuiCompressor.

  • Source images (PNG), run through Pngquant via a Phing task, which generates compressed images.

Now, being kind of new to the idea of asset publishing, I would like to have Yii 2 to take care of (allmost) all of this. I want these source files somewhere outside my webroot. Then, Asset Manager should only publish the generated, compressed files.

I’ve tried creating an asset bundle, specifying $sourcePath, but it publishes all my source files too. So I tried to create a beforeCopy callback (by this example).

So far, with no success.

So, can anyone tell me what should be the best approach of achieving this?