1

I am trying to get CSS and JS minification set up in a Symfony project using assetic. I can not use java or node.js or anything like that, so I was following the directions at Symfony2 minify without java or node by userlond to get the filters in assetic that use minify to do it for me.

I followed the instructions and have installed minify via composer, but I keep getting the following when I do an assetic dump:

php.CRITICAL: Fatal Error: Class 'JSMinPlus' not found {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 0): Error: Class 'JSMinPlus' not found at /var/www/html/new_test_1/vendor/kriswallsmith/assetic/src/Assetic/Filter/JSMinPlusFilter.php:32)"}

[Symfony\Component\Debug\Exception\ClassNotFoundException]      
  Attempted to load class "JSMinPlus" from the global namespace.  
  Did you forget a "use" statement?

If I don't try use the jsminplus filter, but am still using the minifycsscompressor filter, it all seems to work fine (and I get my CSS minified).

Has something changed in the minify project that has created an incompatibility or something?

The code I am using in the TWIG template is:

{% javascripts
    '@TemplateBundle/Resources/public/media/site-assets/javascript/vendor/jquery-1.12.1.min.js'
    '@TemplateBundle/Resources/public/media/site-assets/javascript/vendor/*.js'
    '@TemplateBundle/Resources/public/media/site-assets/javascript/*.js'
    filter='jsminplus'
%}

    <script src="{{ asset_url }}"></script>

{% endjavascripts %}

If I take out the filter='jsminplus' line, it all works fine (and is just not minified).

0

1 Answer 1

3

The answer you are basing this on is outdated, assetic changed since then. So unless you are specifically using an older version of Symfony you will need something along the lines of

# app/config/config.yml
assetic:
    filters:
        jsqueeze: ~
        # ...

Then

{% javascripts filter="?jsqueeze" output="js/app.js"
    "@TemplateBundle/Resources/public/media/site-assets/javascript/*.js"
    "@TemplateBundle/Resources/public/media/site-assets/javascript/vendor/*.js"
    "@TemplateBundle/Resources/public/media/site-assets/javascript/*.js"
%}
    <script src="{{ asset_url }}"></script>
{% endjavascripts %}

Watch out that the ? in ?jsqueeze means this will only be minified in prod environment.

See the documentation for a non javascript minifying solution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.