[英]How to configure grunt-contrib-uglify to minify files while retaining directory structure
如果我在下面發布的示例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自述文件有一個明確的解釋
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.