How to get assetic to update assets in dev enviroment in symfony2? - symfony

I have the issue that my assets, e.g. my sass and javascript, did not recompile on file modification. I installed I accessed them via symlink option and access the dev environment via localhost:8000. I have to manually call /app/console assetic:dump for them to update.
How do I get assetic to watch for file modification?

You can also use
php app/console assetic:dump --watch
If you want to watch for file modifications. This will re-run assetic:dump in the background automatically for you.
And yes dont forget if you use dev then access your site via app_dev.php
And small note... when you use production environment then make sure you execute assetic:dump with --env=prod (without --watch as well)

I realized I have to access the dev page with app_dev.php:
localhost:8000/app_dev.php/

Try to execute:
php app/console assetic:dump --env=dev

Related

Put environment in prod and remove the profiler Symfony 4

I am putting my website in production, but I have a problem with the environment.As you can see in the screenshot below, the site remains in "dev" mode
However, I already modify my .env file as follows:
APP_ENV=prod
APP_DEBUG=0
APP_SECRET=secretthings
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS=localhost,example.com
###< symfony/framework-bundle ###
should I change another file or do something else so that my site is finally operational?
Thank you for your answers
Did you try to clear your cache?
Move to your project and type php bin/console cache:clear. You can also pass the enviroment you want to clear with php bin/console cache:clear --env=prod. Use dev or prod as your parameter.
Edit: If you have a .env.local file - you need to change your enviroment there.
After you update your .env file you should run composer dump-env prod to compile your environment file for production use.

Symfony assetic issue file does not exist

I tried to resolve my problem all this morning but I didn't find the solution anywhere.
I have a Symfony project and I use Assetic for my css and js files.
Till today when I ran php bin/console assetic:dump --env=prod, it worked fine.
But now I have this error :
[Symfony\Component\Config\Exception\FileLocatorFileNotFoundException]
The file "C:\wamp\www\PLIE08\app/config/config_=prod.yml" does not exist.
I don't understand why it adds = in my file.
Moreover, after running this command I realized that a folder called "=prod" is created in var/cache in addition to the dev and prod folder.
I tried to update, install composer, clear the cache, look in config file if something was wrong but I'm still blocked...
Somebody can tell me why it searchs the bad file ?
Thanks
try this command bin/console assetic:dump -e prod to verify duplicated =. Otherwise remove the entire content of the cache/prod folder, doest not clear:cache, remove all manually.

how to reload a javascript asset in Symfony2?

I have the code below (it's in my twig file) to attach a javascript file specific to this template.
<script type="text/javascript" src="{{ asset("bundles/myappmybundle/js/jobs.js") }}"></script>
It is working fine EXCEPT the fact even if I made changes to the javascript file, somehow my browser (firefox with firebug) is still loading a previous version.
I've tried:
clearing cache via php app/console
rm -rf app/cache/*
Any ideas on how to fix this?
Thanks a lot
It might be in two cases:
Your browser cached this js for you. Try to clear cache of your browser
You installed assets once with hard-copy option (by default). And after you changed files you didn't update your assets with php app/console assets:install.
To make your assets always synced with your bundle's code you can just run in CLI:
php app/console assets:install --symlink
It will create symlink to src/YourBundle/Resources/public folder in the /web/bundles/

symfony2 assets in changed web folder

I'm using Symfony2 in my project and I changed web root ditectory. I followed instructions on this page http://symfony.com/doc/current/cookbook/configuration/override_dir_structure.html. Now my project structure looks like this:
/frontend - the new web root dir
/myproject - the project dir
Then i'm installed and dumped assets
php app/console assets:dump
php app/console assetic:install ../frontend --symlink
Most things works fine. But the problem is that I can't acces to any asset in /bundles directory, Symfony returns error
No route found for "GET /bundles/..."
But I can see my assets in this directory in explorer (symlinks created correctly).
Is your web server configured to follow symlinks? Without knowing which web server you are using, as an example in apache you need to set the FollowSymLinks option. Alternatively, remove the symlink option when doing assets:install.
Also, it's probably just a typo, but you've got the commands for installing assets and dumping assetic a bit muddled in your question - should be something like this:
php app/console assets:install --symlink ../frontend
php app/console assetic:dump -e dev

symfony2 assets:install output directory

I am trying to change the default "web" directory of symfony to something else for example public_html.
I got most of it working by following the manual here -> http://symfony.com/doc/master/cookbook/configuration/override_dir_structure.html
Very last part of that document explains how to change assetic so that assetic:dump will output to the correct directory, so that works, and the website also works.
However the document doesn't seem to explain how to change the output directory of the assets:install command.
When i run this command it still outputs to the web directory.
Does anybody know how to change this ?
assets:install requires a parameter telling where to install the assets:
app/console assets:install path
Just provide your path instead of web.
You can set a path parameter to assets:install
But I think in some case better not overriding the directory structure, preferably making a symlink to the web dir.

Resources