Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grunt js tasks and files naming with multiple dots

I'm uglifying files with one to one mapping like this:

    plugins: {
        files: [{
            expand: true,
            src: '*.js',
            cwd: 'Scripts/v1/Plugins',
            dest: 'Scripts/v1/Build/Plugins',
            ext: '.min.js'
        }]
    },

And this works fine, until i start naming my files with multiple dots in filename. So above script will uglify
4 files:
plugins.a.js
plugins.b.js
plugins.c.js
plugins.d.js

into one file:

plugins.min.js

while I expect:

plugins.a.min.js
plugins.b.min.js
plugins.c.min.js
plugins.d.min.js

Is this expected behavior or bug? In any case how can I keep one to one mapping with my naming convention.

like image 377
Sergej Popov Avatar asked Dec 12 '22 15:12

Sergej Popov


2 Answers

Did you manage to find a solution for this? I checked all the issues in their github and apparently it should be fixed, but I'm still getting the same behavior with the latest builds.

EDIT: A solution was to pass a rename function and manually create the filename

files: {
            src: 'src/hp-lp-<%= pkg.version %>.js',
            dest: 'src/',
            expand: true,
            flatten: 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';
            }
        }
like image 81
woutr_be Avatar answered Dec 20 '22 21:12

woutr_be


It is currently the default expected behavior.

This has been brought up a few times with grunt:

  • https://github.com/gruntjs/grunt-contrib-uglify/issues/54
  • extension is after last period only

From the first link, a change has been submitted to node globule that will let you select either first or last dot.

Other than that (or until that lands) you could use a rename function to get the behavior you need.

like image 20
dc5 Avatar answered Dec 20 '22 19:12

dc5