Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Organizing assets in Symfony3

I still have some problems to handle my assets in symfony. The best practices say, I should store my assets in web/. But I dont like to store my raw sass files there, because its a public folder and I think only compiled or static files should be stored there.

Thats why I store them (js and sass) currently in app/Resources. And my assetic.read_from is app/Resources. But then there are some bundles, that are symlinked by assets:install to web/bundles/.

And now, when I want to include this bundle-assets in my twig files, I have to go there by ../../web/bundles/.. in the stylesheets block. That doesnt look very clean, so I did a symlink app/Resources/bundles->web/bundles/ and that works.

But I still think its too much fiddle and I would like to know if there is a cleaner way that better collects my assets in one place.

like image 726
Asara Avatar asked Aug 03 '16 15:08

Asara


1 Answers

Don't use AsseticBundle, it was even removed in default symfony-standard 2.8. Managing frontend assets with php is workaround for someone who really don't want to use "the right tools"

I personally keep my source files in /assets/ and with Grunt JS I compile them to /web/assets/ which later is served from assets.somedomain.com through CDN

2 years ago I wrote post about managing assets with symfony, it's still valid and up to date. You might want to check it out.

http://konradpodgorski.com/blog/2014/06/23/better-way-to-work-with-assets-in-symfony-2/

I should extend post by things I learned since then but always not enough time :)

like image 144
Konrad Podgórski Avatar answered Nov 03 '22 01:11

Konrad Podgórski