简体   繁体   English

Grunt缩小了内联css

[英]Grunt minify inline css

Are there any grunt plugin just for minifying inline css? 是否有任何grunt插件只是为了缩小内联css? I am using grunt-critical for injecting inline css. 我正在使用grunt-critical来注入内联css。 Is there any grunt plugin to minify the inline css of all html files in 1 folder? 是否有任何grunt插件来缩小1个文件夹中所有html文件的内联css? I have tried grunt-htmlprocessor and it does only to minify the html code. 我尝试过grunt-htmlprocessor,它只是为了缩小html代码。

Take a look at this one: it'll do the same thing grunt-critical is doing for you but will also minify the CSS before pasting it inline, so it will effectively do the task you want it to do: 看一下这个:它会做同样的事情,grunt-critical正在为你做,但也会粘贴内联之前缩小CSS,所以它会有效地完成你想要它做的任务:

https://github.com/chyingp/grunt-inline https://github.com/chyingp/grunt-inline

cssmin cssmin

If cssmin is assigned true, .css will be minified before inlined. 如果cssmin指定为true,则.css将在内联之前缩小。

You could write a regular expression that removes all spaces between style=" and " . 您可以编写一个正则表达式来删除style=""之间的所有空格。 It would require a fair amount of work, but it's the only solution I know of at this time. 这需要相当多的工作,但这是我目前唯一知道的解决方案。

Try it! 试试吧!

Usage: 用法:

cssmin: {
  target: {
    files: [{
      expand: true,
      cwd: 'public/css',
      src: ['*.css', '!*.min.css'],
      dest: 'public/css',
      ext: '.min.css'
    }]
  }
}

https://github.com/gruntjs/grunt-contrib-cssmin https://github.com/gruntjs/grunt-contrib-cssmin

Minify is an option which is set to false by default. Minify是一个默认设置为false的选项。 You can see the full list of options here 您可以在此处查看完整的选项列表

// example from https://www.npmjs.com/package/grunt-critical

critical: {
    test: {
        options: {
            base: './',
            css: [
                'test/fixture/styles/main.css',
                'test/fixture/styles/bootstrap.css'
            ],
            minify:true,
            width: 320,
            height: 70
        },
        src: 'test/fixture/index.html',
        dest: 'test/generated/index-critical.html'
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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