After running
php app/console assetic:dump --env=prod
all the assets are dumpped.
Is there any way to dump only 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?
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.
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
I have my own hard tricky solution for a similar problem cause i need dump assets not present on twig templates coming from database or json file.
With asset name only, i don't understand how you could do it without further explanation. If you print $name value when run assetic dump, you get something like 'afd49f7'. Symfony2 reads all javascripts and stylesheets blocks on twig templates and assign this key name automatically.
If you try to minify one file manually you better use yui-compressor or similar directly, otherwise if you really need dump a collection of assets to one file (A collection could contain only one file) or single file but using symfony2 you must use "named assets" and something like the command suggested by parla. See the proper section on How to Use Assetic for Asset Management and also check AsseticBundle Configuration.
Anyway the command above don't works on Symfony2 v2.3 (LTS) cause dumpAsset method is declared as private on DumpCommand, and AbstractCommand not exists.
If you use Symfony2 v2.3, you need rewrite the entire command adding option --name
and changing ->setName('assetic:dump')
for something else.
© 2022 - 2024 — McMap. All rights reserved.