Comments (3)
A symfony-command could look like this (not deeply integrated, but it does the job) - extend it for your needs:
<?php
namespace App\Command;
use Assetic\Factory\AssetFactory;
use Assetic\Filter\CSSMinFilter;
use Assetic\Filter\CssRewriteFilter;
use Assetic\Filter\JavaScriptMinifierFilter;
use Assetic\FilterManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class DumpAssetsCommand extends Command
{
protected static $defaultName = 'app:dump-assets';
protected static $defaultDescription = 'Add a short description for your command';
/** @var string */
protected $projectDir;
/** @var bool */
protected $kernelDebug;
/** @var AssetFactory|null */
protected $assetFactory;
public function __construct(string $projectDir, bool $kernelDebug, string $name = null)
{
$this->projectDir = $projectDir;
$this->kernelDebug = $kernelDebug;
parent::__construct($name);
}
protected function configure(): void
{
$this
->setDescription(self::$defaultDescription);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$cssFile = $this->buildCssFiles();
$output->writeln('css-files dumped to '.$cssFile);
$jsFile = $this->buildJsFiles();
$output->writeln('js-files dumped to '.$jsFile);
return Command::SUCCESS;
}
protected function getAssetFactory(): AssetFactory
{
if ($this->assetFactory === null) {
$filterManager = new FilterManager();
$filterManager->set('cssrewrite', new CssRewriteFilter());
$filterManager->set('cssmin', new CSSMinFilter());
$filterManager->set('jsmin', new JavaScriptMinifierFilter());
$this->assetFactory = new AssetFactory($this->projectDir.'/public');
$this->assetFactory->setDebug($this->kernelDebug);
$this->assetFactory->setFilterManager($filterManager);
}
return $this->assetFactory;
}
protected function buildCssFiles(): string
{
$css = $this->getAssetFactory()->createAsset([
'css/bootstrap-night.min.css',
'css/bootstrap-icons.css',
'css/tom-select.bootstrap5.min.css',
'css/sweetalert2.min.css',
'css/style.css',
], [
'cssrewrite',
'?cssmin',
]);
$filePath = $this->projectDir.'/public/site.css';
file_put_contents($filePath, $css->dump());
return $filePath;
}
protected function buildJsFiles(): string
{
$js = $this->getAssetFactory()->createAsset([
'js/bootstrap.bundle.min.js',
'js/chart.min.js',
'js/tablesort.min.js',
'js/tablesort.number.min.js',
'js/clipboard.min.js',
'js/tom-select.complete.min.js',
'js/sweetalert2.min.js',
'js/script.js',
], [
'?jsmin',
]);
$filePath = $this->projectDir.'/public/site.js';
file_put_contents($filePath, $js->dump());
return $filePath;
}
}
from assetic.
Not sure tbh, we use it with @wintercms and we don't use the Twig integration. What sort of issues have you run into so far?
from assetic.
Following config works for me (symfony 5.4):
# services.yaml
app.assetic.factory:
class: Assetic\Factory\AssetFactory
arguments:
- '%kernel.project_dir%/public/assets'
- '%kernel.debug%'
Assetic\Extension\Twig\AsseticExtension:
arguments:
- '@app.assetic.factory'
tags:
- 'twig.extension'
Then use twig-tags as documented. Whats missing is a command similar to assetic:dump
in sf 3.4, which dumps the files once at deployment.
from assetic.
Related Issues (13)
- Support for enabling compass in ScssphpFilter should be removed HOT 1
- Custom functions in ScssphpFilter are not exposing the full upstream API HOT 7
- CssMin not found error when using the filter CssMinFilter HOT 1
- What happend to `CompilerJarFilter`? HOT 2
- Change property scopes to protected? HOT 5
- Removal of the Assetic\Extension\Twig\TwigFormulaLoader class HOT 10
- php 8.0 HOT 4
- JSMin not found when using JSMinFilter HOT 1
- PHP Fatal error: Interface 'Assetic\Factory\Worker\WorkerInterface' not found. HOT 3
- Add support for SVG sanitization
- Hidden API for registerFunction in LessphpFilter HOT 2
- Universal selector can't follow a comment
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from assetic.