如果我在下面发布的示例 Gruntfile 中的“js”目录下有多个子目录,并且想将子目录保留在不同的目标目录下,我该怎么做?
例如
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' ]);
};
在这种情况下,我已经显示了 */.js,但即使我明确指定单个子目录,如 js/xyz/*.js,它也不会复制目录结构,而是在示例中,它似乎将文件放在 minJs/文件夹下的子目录中。我在这里错过了什么?请帮忙。
谢谢,
水稻
最佳答案
将 flatten 属性设置为 false。
在grunt copy github readme上有明确的解释
https://github.com/gruntjs/grunt-contrib-copy
摘录:
$ 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
关于javascript - 如何配置 grunt-contrib-uglify 以在保留目录结构的同时缩小文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18613164/