是否有模块或 gulp 选项可以将 html 和 css 缩小为一行?
例如
<style media='screen' type='text/css'>
.text {
padding: 1px 1px 1px 1px;
font-size: 12px;
}
</style>
<!-- now for html -->
<div style='width:550px;' >
<div style='float:left;font-size:1.2em;' class='text'>
Title goes here
</div>
<div style='width:60px;float:left;' class='text'>
<span style='font-size:0.8em;'>
®
</span>
</div>
<div style='float:left' class='text'>
Some paragraph text
</div>
<div style='float:left;padding-top:10px;' class='text'>
<span style='font-style:italic;'>
A footer to the paragraph
</span>
</div>
</div>
我可以使用node.js 将上面的内容缩小到一行,使其看起来像下面这样吗?
<style media='screen' type='text/css'>.text {padding: 1px 1px 1px 1px;font-size:12px;}</style><!-- now for html --><div style='width:550px;' > <div style='float:left;font-size:1.2em;' class='text'>MY BRILLIANCE</div><div style='width:60px;float:left;' class='text'> <span style='font-size:0.8em;'>®</span> </div> <div style='float:left' class='text'> With release comes growth, through challenge comes wisdom, let us show you the way. </div> <div style='float:left;padding-top:10px;' class='text'><span style='font-style:italic;'>Absolute Equal Acceptance through Thought, Conscience and Reunion.</span></div></div>
最佳答案
有一个非常受欢迎的软件包,名为 html-minifier
.
网站上的一个最小示例:
var minify = require('html-minifier').minify;
var result = minify('<p title="blah" id="moo">foo</p>', {
removeAttributeQuotes: true
});
result; // '<p title=blah id=moo>foo</p>'
关于html - 在 Node.js 中将 html 和 CSS 缩小到一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56598505/