kriswallsmith / assetic

Asset Management for PHP
MIT License
3.75k stars 555 forks source link

Unclear how to write/dump assets #840

Open thepurpleblob opened 7 years ago

thepurpleblob commented 7 years ago

I don't believe the docs give sufficient information to enable one to write assets to a file. I eventually got the idea from http://stackoverflow.com/questions/14538335/assetic-unable-to-write-assets plus digging through the code to discover that setTargetPath() also applies to collections (the docs don't say that).

As this is probably a common scenario a worked example would have saved some time.

Just in case it helps anybody else (caveat - I'm still experimenting with this), this is what I did (simplified)

        $am = new AssetManager();
        $css = new AssetCollection(array(
            new FileAsset('/path/to/app/src/assets/css/bootstrap/bootstrap.min.css'),
        ));
        $css->setTargetPath('combined.css');
        $am->set('css', $css);
        $writer = new AssetWriter('/path/to/app/cache/');
        $writer->writeManagerAssets($am);