<style>
body{
margin:0;
padding:0;
}
</style>
<body>
<ul>
<li>list-1</li>
</ul>
</body>
<script>
$("ul li").on("click",function(){
console.log($(this).html())
})
</script>
使用gulp 的gulp-htmlmin插件对 上边的html进行压缩,得到的结果只是对body里面的html代码进行了压缩;
但是理想的情况是将上边代码的css,html,js一起压缩。有什么方法吗?是需要在HTML中再进行css压缩一次还是有其他的插件?
请使用gulp-useref: https://github.com/jonkemp/gulp-useref
对于页面内的CSS或JS代码(建议将代码提出来放入单独的文件)当然如果你一定要这么干,方法也是有的,https://github.com/knpwrs/gulp-cheerio 这个插件可以搞定,它可以帮助你解析html页面,然后你拿到script或者style标签里的内容用node中uglify和minifyCSS进行压缩就OK啦!
更多内容参考这个 https://github.com/Platform-CUF/use-gulp