简体   繁体   中英

Embed CSS into HTML file with Grunt

I need to replace tags in HTML file like this:

<link type="text/css" rel="stylesheet" href="template.css">

With the following:

<style type="text/css"> { /* content of template.css */ } </style>

Using Grunt .

What is the best way of achieving this?

Convert your HTML file to a Twig template. Embed your CSS file with {% include %} operator. Then use consolidate.js with atpl.js through grunt-consolidate plugin to compile it.

Twig is used in Symfony2 project and based on Django template language and is one of the most elegant and powerful ones for server-side compilation.

If you want you can use another compiler with include functionality, cause Consolidate , supports lots of them .

See the provided links for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM