Grunt js tasks and file names with multiple dots

I clean one-on-one files as follows:

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

And that works fine until I start naming my files with a few dots in the file name. So the above script will guess
4 files:
plugins.a.js
plugins.b.js
plugins.c.js
plugins.d.js

into one file:

plugins.min.js

when i expect:

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

Is this the expected behavior or error? In any case, how can I match one to one with my naming convention.

+4
source share
3 answers

This is currently the expected default behavior.

This was raised several times with a grunt:

From the first link, a change was made to the node globule , which allows you to select the first or last point.

Besides this (or until then) you can use the rename function to get the desired behavior.

+3
source

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

EDIT: the solution was to pass the rename function and manually create the file name

 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'; } } 
+6
source

Use extDot instead of ext:

In Grunt, this way you can match file names with multiple points and write down the names of files that contain the original sequence of points, except for the file extension.

i.e.

 /path/to/module.somename.scss -> /path/to/module.somename.css 

Example:

 files: [{ expand: true, src: ['public_html/**/*.scss'], extDot: 'first', rename : function (dest, src) { var _new_ext = 'css'; //Get src filename src = src.split("/"); var filename = src.pop(); //Apply new extension to filename var arr = filename.split("."); arr.pop(); arr.push(_new_ext); filename = arr.join("."); dest = dest || src.join("/"); return dest + '/' + filename; } }] 

Essence: https://gist.github.com/tecfu/f84a65ffa850a0bc2e88

+3
source

Source: https://habr.com/ru/post/1481355/


All Articles