简体   繁体   English

如何禁用grunt-contrib-cssmin组合?

[英]How to disable grunt-contrib-cssmin combine?

I have three files: 我有三个文件:

'selectize.default.css'
'selectize.pagination.css'
'selectize.patch.css'

and I want to minimize them. 我想尽量减少它们。

Here is my gruntfile: 这是我的gruntfile:

cssmin: {
     min: {
         files: [{
             expand: true,
             cwd: 'css',
             src: [
               'selectize.default.css',
               'selectize.pagination.css',
               'selectize.patch.css',
               '!*.min.css'
             ],
             dest: 'release/css',
             ext: '.min.css'
         }]
     }
}

Problem is there is only one file named selectize.min.css I don't want it to minimize only one file. 问题是只有一个名为selectize.min.css文件我不希望它只减少一个文件。 How can I minimize all three of them? 我怎样才能最大限度地减少这三个呢?

So this ticket is kind of old, but as Peng Lin so eloquently stated above, the selected answer is inadequate for most programmers since it requires too much manual adjustment. 所以这张票有点陈旧,但正如彭林上面雄辩地说的那样,对于大多数程序员来说,选择的答案是不够的,因为它需要太多的手动调整。 It's not maintainable. 这是不可维护的。

Grunt has a way of specifying where the extension dot is in file names. Grunt有一种方法可以指定扩展点在文件名中的位置。 By default, it's set to the first one which effectively changes the file names on output. 默认情况下,它设置为第一个有效更改输出文件名的文件。 The property is called extDot. 该属性称为extDot。 You can read about it Here if you want. 如果你愿意,你可以在这里阅读。

If you set it to last , it will preserve your file names and your original example will work. 如果将其设置为最后 ,它将保留您的文件名,并且您的原始示例将起作用。

Example: 例:

cssmin: {
  min: {
     files: [{
         expand: true,
         cwd: 'css',
         src: [
           'selectize.default.css',
           'selectize.pagination.css',
           'selectize.patch.css',
           '!*.min.css'
         ],
         dest: 'release/css',
         ext: '.min.css',
         extDot: 'last'   // Extensions in filenames begin after the last dot
     }]
 }  }

Hope this helps someone in the future. 希望这可以帮助将来的某个人。

If I understand your question correctly, you want to minimize the files, but not combine them into one? 如果我正确理解您的问题,您希望最小化文件,但不要将它们合并为一个? In that case, my recommendation would be to make separate calls for each file. 在这种情况下,我的建议是为每个文件单独调用。 eg: 例如:

cssmin: {
     default: {
         files: [{
             expand: true,
             cwd: 'css',
             src: [
               'selectize.default.css',
             ],
             dest: 'release/css',
             ext: '.min.css'
         }]
     },
     pagination: {
         files: [{
             expand: true,
             cwd: 'css',
             src: [
               'selectize.pagination.css',
             ],
             dest: 'release/css',
             ext: '.min.css'
         }]
     },
     patch: {
         files: [{
             expand: true,
             cwd: 'css',
             src: [
               'selectize.patch.css',
             ],
             dest: 'release/css',
             ext: '.min.css'
         }]
     },
 }

It probably isn't the cleanest way, but it will do what you want. 它可能不是最干净的方式,但它会做你想要的。 I haven't test this code, so be warned I don't know that it works. 我没有测试这段代码,所以请注意我不知道它是否有效。

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

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