Configure Grunt File Name Matching for Files with Multiple Dots

后端 未结 3 1473
北恋
北恋 2020-12-24 13:52

I just started using grunt, and love it. I keep running into an issue that seems like it might be pretty common. Here it is. I have files named so that words after a dot are

相关标签:
3条回答
  • 2020-12-24 14:33

    Note that there is another option "extDot" that you can use to specify after which dot the ext should apply (first or last):

    E.g.

    files: [{
      expand: true,
      src: ['*.js','!*min.js'],
      dest: 'js',
      cwd: 'js',
      ext: '.min.js',
      extDot: 'last'
    }]
    
    0 讨论(0)
  • 2020-12-24 14:52

    Take a look at the "Building the files object dynamically" section of Configuring Tasks.

    Instead of specifying ext, you can specify rename which is a function that lets you create your own mapping for the file names.

    The problem you are running into was brought up as an issue on github and the answer from the grunt folks was that the "extension" of a file should be everything after the first "." instead of the last.

    Hope that helps you!

    0 讨论(0)
  • 2020-12-24 14:57

    That's the workaround I'm using in my projects:

    uglify  : {
      build : {
        src     : ['**/*.js', '!*.min.js'],
        cwd     : 'js/',
        dest    : 'js/',
        expand  : true,
        rename  : function (dest, src) {
          var folder    = src.substring(0, src.lastIndexOf('/'));
          var filename  = src.substring(src.lastIndexOf('/'), src.length);
    
          filename  = filename.substring(0, filename.lastIndexOf('.'));
    
          return dest + folder + filename + '.min.js';
        }
      }
    }
    

    When the filename is like jquery.2.0.3.js then after minifying that it will be jquery.2.0.3.min.js.

    0 讨论(0)
提交回复
热议问题