Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (47 sloc) 1.78 KB

Install the UglifyJS and UglifyCSS using npm locally.

Now starts with UglifyJS first. Go to your Symfony root folder and type below command.

cd /path/to/your/symfony/project
npm install uglify-js --prefix app/Resources

It will install UglifyJS locally on your app/Resources/node_modules/.bin/uglifyjs.

From here you can execute

./app/Resources/node_modules/.bin/uglifyjs --help

To test your installation of UglifyJS is success.

Now install UglifyCSS. Go to your Symfony root folder and type below command.

cd /path/to/your/symfony/project
npm install uglifycss --prefix app/Resources

It will install UglifyCSS locally on your app/Resources/node_modules/.bin/uglifycss.

Now open config.yml and edit like below.

# app/config/config.yml
assetic:
    # the path to the node executable and maybe different with your system
    node: /usr/bin/nodejs
    filters:
        uglifyjs2:
            # the path to the uglifyjs executable
            bin: bin: %kernel.root_dir%/Resources/node_modules/.bin/uglifyjs
        uglifycss:
            bin: %kernel.root_dir%/Resources/node_modules/.bin/uglifycss
            ugly_comments: true

Until now your Symfony already installed with UglifyJS and UglifyCSS and let's use it on your Twig like below.

{% javascripts '@AppBundle/Resources/public/js/*' filter='uglifyjs2' %}
    <script src="{{ asset_url }}"></script>
{% endjavascripts %}

and

{% stylesheets '@AppBundle/Resources/public/js/style.css' filter="uglifycss" %}
    <link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}

Now delete your Symfony cache and try to access the website and now your minification of JS and CSS should be success.

References:

You can’t perform that action at this time.