How to configure grunt-contrib-uuglify to minimize files while maintaining directory structure


In case I have several subdirectories in the "js" directory in the Gruntfile example below and want to save the subdirectories in another destination directory, how do I do this?

For instance,

module.exports = function (grunt) { grunt.initConfig({ // define source files and their destinations uglify: { files: { src: 'js/**/*.js', // source files mask dest: 'minJs/', // destination folder expand: true, // allow dynamic building flatten: true, // remove all unnecessary nesting } } }); // load plugins grunt.loadNpmTasks('grunt-contrib-uglify'); // register at least this one task grunt.registerTask('default', [ 'uglify' ]); }; 

In this case, I showed * /. js, but even if I explicitly specify one subdirectory such as js / xyz / *. js, then it also does not copy the directory structure, instead it seems to put the files inside a subdirectory in the mini-directory / folder in the example. What am I missing here? Please, help.

Thanks,
Paddy

+6
source share
1 answer

Set the flatten property to false.

There is a clear explanation for a copy of guntub github readme

https://github.com/gruntjs/grunt-contrib-copy

Excerpts:

 $ grunt copy Running "copy:main" (copy) task Created 1 directories, copied 1 files Done, without errors. $ tree -I node_modules . ├── Gruntfile.js ├── dest │ └── src │ ├── a │ └── subdir └── src ├── a └── subdir └── b 5 directories, 4 files Flattening the filepath output: copy: { main: { expand: true, cwd: 'src/', src: '**', dest: 'dest/', flatten: true, filter: 'isFile', }, }, $ grunt copy Running "copy:main" (copy) task Copied 2 files Done, without errors. $ tree -I node_modules . ├── Gruntfile.js ├── dest │ ├── a │ └── b └── src ├── a └── subdir └── b 3 directories, 5 files 
+5
source

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


All Articles