New in Symfony 2.6: Smarter assets:install command

Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Contributed by
Roy Van Ginneken
in #11312.
The assets:install
command is one of the trickiest things for Symfony newcomers.
This command is used to install the web assets (CSS, JavaScript, images) for
the production application. When executed without options, the command copies into
web/
all the files found in the Resources/public/
directories of your
application and bundles.
Although developers usually execute the command without any option, most of the
time it's better to execute it with the --symlink
option. This makes a symbolic
link of your assets instead of actually copying their files. This means that any
change in the content of the web assets will have immediate effect in the application.
The problem is that the --symlink
option will throw an InvalidArgumentException
if your system doesn't support symbolic links. That's why, starting from Symfony 2.6,
the behavior of the assets:install command will be smarter. Now, when your
system doesn't support symbolic links or if there is any other problem, the
command will silently fall back to make a hard copy of the assets and it will
inform you about this:
1 2 3 4 5 6 7 8
# make a hard copy of the assets in web/
$ php app/console assets:install
# if possible, make absolute symlinks in web/ if not, make a hard copy
$ php app/console assets:install --symlink
# if possible, make relative symlinks in web/ if not, make a hard copy
$ php app/console assets:install --symlink --relative
In short, starting from Symfony 2.6, the best practice is to always pass the
--symlink
option to the assets:install
command.
This improvement was originally proposed by Ryan Weaver in the issue #11297 and it's part of the Symfony DX initiative. We'd like to thank the help provided by Andre Rømcke, from the eZ Publish community, Bruno Škvorc and Pascal Borreli.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Why didn't you put --symlink automatic then ? And in another hand add the --hardcopy option.
Regarding why is this behavior not enabled by default, I guess it has to do with the "backwards compatibility" policy. We cannot change this behavior in Symfony 2.x versions. That's why I've added a new proposal to the list of BC-breaks for Symfony 3: https://github.com/symfony/symfony/issues/11742
"symfony-assets-install": "symlink"