Using the new asset management system
The asset management system is the most recent one to Drupal 8. The asset management system allows modules and themes to register libraries. Libraries define CSS style sheets and JavaScript files that need to be loaded with the page. Drupal 8 takes this approach for the frontend performance. Rather than loading all CSS or JavaScript assets, only those required for the current page in the specified libraries will be loaded.
In this recipe, we will define a libraries.yml
file that will define a CSS style sheet and JavaScript file provided by a custom theme.
Getting ready
This recipe assumes that you have created a custom theme, such as the one you created in the first recipe. When you see mytheme
in this recipe, use the machine name of the theme that you created.
How to do it...
- Create a folder named
css
in your theme's base directory. - In your
css
folder, add astyle.css
file that will hold the theme's CSS declarations. For the purpose of demonstration, add...