html - 在 Node.js 中将 html 和 CSS 缩小到一行

标签 html node.js gulp node-modules minify

是否有模块或 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/

相关文章:

javascript - Node Express passport (JWT) - 授权后回调

javascript - 如何使用 Gulp 连接 CSS 文件?

angularjs - 无法读取未定义gulp的属性 'apply'

javascript - Elixir : How to Watch a Public Directory for Change?

HTML 5 视频播放器全屏不工作

html - 使用 sed 加入 html 行

python - Node js 与 Python 中一种 sha256 哈希值的比较

node.js - Spotify Node Web api - 多个用户的问题

javascript - 将模式中的图像选择应用到页面背景中

javascript - 如何在 Angular 指令的链接函数中插入 html?