kriswallsmith / assetic

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

Wrong name for output files in debug mode #728

Open xpr0ger opened 9 years ago

xpr0ger commented 9 years ago

For version 1.2.1

In debug mode I'm getting wrong names for output files.

For example, in template I got the name for the css file "css/3c39bd2_main_1.css", but the file has generated under "css/3c39bd2.css". In case when the mode debug is disabled, everything is ok.

$factory = new \Assetic\Factory\AssetFactory($assetsPath, $config->getParam('app.debug')); 
$factory->setDefaultOutput($outputPath);
$factory->setFilterManager($container->get('assets.filterManager'));
$factory->setAssetManager(new \Assetic\Factory\LazyAssetManager($factory));
$twig = new \Twig_Environment($loader, [
           'debug' => $config->getParam('app.debug'),
           'cache' => PATH_BASE . DS . $config->getParam('tpl.cache'),
]);
$twig->addExtension(new \Assetic\Extension\Twig\AsseticExtension($container->get('assets.factory')));
$assetManager = $this->assetFactory->getAssetManager();
$assetManager->setLoader('twig', new TwigFormulaLoader($this->twig));

foreach ($templates as $template) {
        $res = new TwigResource($this->twig->getLoader(), $template);
        $assetManager->addResource($res, 'twig');
}

$this->writer->writeManagerAssets($assetManager);
{% stylesheets filter='sass,?ucss' 'sass/main.sass' %}
        <link href="{{ asset_url }}" type="text/css" rel="stylesheet"/>
{% endstylesheets %}

How i can solve it or this is a bug?

rymndhng commented 9 years ago

Ack, I'm seeing this issue as well. From digging on the internet, this appears to generate URLs that are routed properly by Symfony's controllers.Is there a workaround for this?

stof commented 9 years ago

by default, assets are not combined in dev, and so a file is dumped for each asset in the asset collection (there is a single asset in the collection in your case).

There is 3 solutions in your case:

Note that if you keep the file combined, you would still need to switch between debug and non-debug mode when dumping your assets, otherwise the file content will either always have ucss applied or never.

rymndhng commented 9 years ago

@stof thanks for the suggestions. combine=true seems reasonable. Let's say I were to explore dumping leaf assets, how would I go about doing that?