Inside my html.html.twig template I've added a stylesheet inside the style elements using this.

{% include directory ~ '/css/base/style.css' %}

Is there a way that I can strip it for all whitespaces? Can I apply the CssOptimizer class to it in any way? Can I also strip the stylesheet for comments?


This is not the right way to integrate a .css file inside a twig file in drupal8. You should use the standard procedure as I mentioned below.

 {{ attach_library('bartik/messages') }} 

SO now for minifying the .css you can use the 3rd party site- https://cssminifier.com/

So the after minifying the .css file, crate the library

      css/components/my-minify.css: {}

Then attach the library in the twig by using the below sysntax

{{ attach_library('your-theme-name/messages') }}

Hope this will help you. If any doubt please don't hesitate to mention.

|improve this answer|||||

Take a look at the Advanced CSS/JS Aggregation module.

|improve this answer|||||
  • Thanks for feedback, i know abour it. As far as i know doesnt output inline css? And i still wonder how to do this using twigs :) – user11448 Dec 27 '16 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy