Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony2: using assetic-dump, is possible to dump just one file?

After running

php app/console assetic:dump --env=prod

all the assets are dumpped.

Is there any way to dump only one file?

like image 559
ziiweb Avatar asked Mar 15 '15 23:03

ziiweb


2 Answers

Looks like you will have to create your own command :

<?php

namespace Your\Namespace\Command;

use Symfony\Bundle\AsseticBundle\Command\AbstractCommand;

class DumpSingleAsset extends AbstractCommand
{
    protected function configure()
    {
        $this
            ->setName('assetic:dump_single_asset')
            ->setDescription('Dumps a single asset')
            ->addArgument('name', InputArgument::REQUIRED, 'The name of the asset')
        ;
    }


    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $name = $input->getArgument('name');
        $this->dumpAsset($name, $output); // Inherited from AbstractCommand
    }
}

Assetic docs shows a way more simple way to dump assets, but I could not find any documentation of the AsseticBundle internals, I just read the code of the Command.

like image 60
DarkChipolata Avatar answered Oct 07 '22 11:10

DarkChipolata


Here's a solution using only configurations. In the config file leave bundles as:

bundles: []

This will not load the assets from any bundle unless you specify it manually.

use named assets as described here to load the assets you want individually.

http://symfony.com/doc/current/cookbook/assetic/asset_management.html#using-named-assets

like image 1
MKoosej Avatar answered Oct 07 '22 10:10

MKoosej