neilime / zf2-assets-bundle

AssetsBundle is a module for Zend Framework 2 allowing asset managment (bundling & caching)
https://neilime.github.io/zf2-assets-bundle/
MIT License
33 stars 20 forks source link

Cached assets files should always preserve relative paths #1

Closed jhuet closed 11 years ago

jhuet commented 11 years ago

I'm having an issue with the css rule in the ZF2 Skeleton that displays the logo as a background image :

div.container a.brand {
    background: url("../images/zf2-logo.png") no-repeat scroll 0 10px transparent;
}

It relates to the path image relatively to the where the css file is. But as all css files are stored at the root of the cache directory - either in production or in dev if you specify them in a specific order like this :

        'cachePath' => '@zfRootPath/public/assets/cache',//cache directory absolute path
        'assets' => array(
            'css' => array(
                'css/bootstrap.min.css',
                'css/style.css',
                'css/bootstrap-responsive.min.css',
            ),
        )

It won't find the image anymore as the final path will be : /assets/images/zf2-logo.png instead of /assets/cache/images/zf2-logo.png

neilime commented 11 years ago

You should cache the "images" directory as explain in simple-configuration-example

'assets' => array(
            'css' => array(
                'css/bootstrap.min.css',
                'css/style.css',
                'css/bootstrap-responsive.min.css',
            ),
            'media' => array('images')
)
jhuet commented 11 years ago

Sorry, i should have given you the whole config file but it is. Here's the whole file :

<?php
return array(
    'asset_bundle' => array(
        'cachePath' => '@zfRootPath/public/assets/cache',//cache directory absolute path
        'assets' => array(
            'css' => array(
                'css/bootstrap.css',
                'css/style.css',
                'css/bootstrap-responsive.css',
            ),
            'js' => array(
                'js/jquery.min.js',
                'js/bootstrap.js'
            ),
            'media' => array('images'),
            'less' => array('@zfRootPath/vendor/twitter/bootstrap/less/bootstrap.less')
        )
    ),
);

And here's how my cache directory looks like for dev :

cache | - images | - | - zf-2-logo.png | - css_bootstrap.css | - css_bootstrap-responsive.css | - css_style.css | - dev_9260a6ead8b3303de4e2c6ea553f8b0f.css | - dev_9260a6ead8b3303de4e2c6ea553f8b0f.less | - js_bootstrap.js | - js_jquery.min.js

Css and js files aren't in a css and js directory thus breaking relative paths.

neilime commented 11 years ago

I think I've fixed your issue, could you please test it ?