Hello.
There was a difficulty in processing paths in Grunt, namely the task concat : how to transfer something from the found paths to the value of the target path?
There is something like this project structure:

src -js --Core ---Core.js ---Something.js ---0_Header.js --FileLoader ---ExternalInterface.js ---Core.js ---Helper.js 

It is necessary that concat collect something like this:

 build -js --Ext ---Core ----Core.min.js ---FileLoader ----FileLoader.min.js 

Something like this would fit here:

 concat: { *** files: { 'build/js/Ext/$1/$1.min.js': ['src/js/(*)/**/*.js'] } *** } 

But it does not work. Separately register each module, when you can clearly automate - it is stupid.
How to register? Thank you.

    1 answer 1

    As an option - to form the desired object with your hands:

     var files = {}; grunt.file.expand("./src/js/*").forEach(function (dir) { var dirname = dir.replace(/^.*[\\\/]/, ''); files['build/js/Ext/' + dirname + '.min.js'] = ['src/js/' + dirname + '/**/*.js']; }); 

    And use in configuration for concat:

     grunt.initConfig({ concat: { dist: { files: files } } }); 

    The alternative is to use the ability to rename dst (a quick fix, does not take into account backslah-i):

     grunt.initConfig({ concat: { dist: { files:[{ expand: true, src: ['src/js/**/*.js'], rename: function (dst, src) { return src.replace(/src\/js\/([^\/]*).*/, 'build/js/Ext/$1/$1.min.js'); } }] } } }); 
    • The idea is good, but it’s easy to search the paths separately, and whether grunt adequate native tools (such as backlinks like regulars or the like) is just the question. But +1 :) - user207618
    • Maybe some of the plugins do this. There seems to be no such possibility in the core (minimatch / node-glob is used). You can feature request to try in grunt-concat . - Vladimir Gamalyan
    • Well, already something :) Thank you. - user207618