Grunt task: Delete lines between markers in an HTML file

后端 未结 2 2035
陌清茗
陌清茗 2021-01-21 07:20

In development we test the unminified css files. On build we compress and combine them. I would like to then remove the uncompressed css link elements between the f

2条回答
  •  滥情空心
    2021-01-21 08:07

    I think that the correct approach here is to have two html files. One which uses the minified version and other which use the normal CSS. You may have index.html containing combined.min.css and dev.index.html having the other files. If you use grunt to change the html then you need another mechanism to revert this operation and leave the file to the original state. This again leads to generating two different files.

    If this doesn't work then you could create a new custom grunt task which reads the content of the file, removes the original css includes and replace them with the minified version:

    var fileContent = '\
    ...\
    \
    \
    \
    \
    ...\
    ';
    
    var minified = '';
    var part1 = fileContent.split("");
    var part2 = part1[1].split("");
    var result = part1[0] + minified + part2[1];
    console.log(result);
    

    The code above produces:

    ......
    

    JSfiddle http://jsfiddle.net/krasimir/WL3bZ/

提交回复
热议问题