Javascript 如何将文件夹的内容复制到另一个文件夹在grunt复制任务中指定文件夹
我在Grunfile.js中剪下了这个:Javascript 如何将文件夹的内容复制到另一个文件夹在grunt复制任务中指定文件夹,javascript,gruntjs,Javascript,Gruntjs,我在Grunfile.js中剪下了这个: copy: { dist: { files: [ { expand: true, dot: true, cwd: '<%= yeoman.app %>', dest: '<%= yeoman.dist %>', src: [
copy: {
dist: {
files: [
{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,txt}',
'.htaccess',
'images/{,*/}*.{webp,gif}',
'styles/fonts/{,*/}*.*',
'bower_components/sass-bootstrap/fonts/*.*',
'bower_components/components-font-awesome/{,*/}*.*',
'bower_components/ckeditor/**/*.*',
'resources/{,*/}*.*'
]
}
]
}
},
复制:{
地区:{
档案:[
{
是的,
多特:没错,
cwd:“”,
目标:'',
src:[
“*.{ico,txt}”,
“.htaccess”,
'images/{,*/}*{webp,gif}',
'样式/字体/{,*/}**',
“bower_components/sass引导/fonts/*.*”,
'bower_components/components font awesome/{,*/}*.*',
“bower_组件/ckeditor/****”,
'resources/{,*/}**'
]
}
]
}
},
这会将所有文件从src:[…]
复制到dist/中的相同文件夹中。如何实现将某些文件直接复制到文件夹中
例如,我不想从/resources复制到“dist/resources”,而是想直接复制到“dist/”
编辑:为了让事情变得清楚:
我希望“/resources”的所有内容都直接位于“/dist”中。因此,例如,如果我有“resources/data/。”,我希望它是“dist/data/。”基本上,资源中的内部文件夹/文件结构应该保留,但根目录现在应该是/dist而不是/resources使用flatte:true,并指定两组文件(一组是展平的,另一组不是) 在这里:
dist:{
档案:[
//所有这些都将(如前所述)与其dir结构一起被复制
{
是的,
多特:没错,
cwd:“”,
目标:'',
src:[
“*.{ico,txt}”,
“.htaccess”,
'images/{,*/}*{webp,gif}',
'样式/字体/{,*/}**',
“bower_components/sass引导/fonts/*.*”,
'bower_components/components font awesome/{,*/}*.*',
“bower_组件/ckeditor/****”,
]
},
//这些会变平的
{
是的,
多特:没错,
扁平化:是的,
cwd:“”,
目标:'',
src:[
'resources/{,*/}**'
]
}
]
}
},
还可以通过在文件对象上实现自定义重命名功能,对文件的最终路径执行转换
更多关于展平和重命名的信息
[更新]
以下是您在更新(更改cwd)中描述的内容
dist:{
档案:[
//所有这些都将(如前所述)与其dir结构一起被复制
{
是的,
多特:没错,
cwd:“”,
目标:'',
src:[
“*.{ico,txt}”,
“.htaccess”,
'images/{,*/}*{webp,gif}',
'样式/字体/{,*/}**',
“bower_components/sass引导/fonts/*.*”,
'bower_components/components font awesome/{,*/}*.*',
“bower_组件/ckeditor/****”,
]
},
{
是的,
多特:没错,
cwd:“/resources”,
目标:'',
src:[
'{,*/}*.*'
]
}
]
}
},
指定一个明确的目标文件夹?我在当前的GrunFile中该如何做?根据,它只是dist/
您可能需要一个单独的gruntjs文件来保存自定义内容。如果我想保留资源中的结构,但将其放入/dist中,该怎么办?然后使用cwd:“/resources”,而不使用flant;)如果我不使用“展平”将文件复制到与以前相同的结构中,但我需要“/resources”的内容直接位于“/dist”中。
dist: {
files: [
// All these are going (as previously) to be copied along with their dir structure
{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,txt}',
'.htaccess',
'images/{,*/}*.{webp,gif}',
'styles/fonts/{,*/}*.*',
'bower_components/sass-bootstrap/fonts/*.*',
'bower_components/components-font-awesome/{,*/}*.*',
'bower_components/ckeditor/**/*.*',
]
},
// These will get flattened
{
expand: true,
dot: true,
flatten: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'resources/{,*/}*.*'
]
}
]
}
},
dist: {
files: [
// All these are going (as previously) to be copied along with their dir structure
{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,txt}',
'.htaccess',
'images/{,*/}*.{webp,gif}',
'styles/fonts/{,*/}*.*',
'bower_components/sass-bootstrap/fonts/*.*',
'bower_components/components-font-awesome/{,*/}*.*',
'bower_components/ckeditor/**/*.*',
]
},
{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>/resources',
dest: '<%= yeoman.dist %>',
src: [
'{,*/}*.*'
]
}
]
}
},