【发布时间】:2017-09-16 18:33:43
【问题描述】:
我正在使用 grunt-contrib-copy。我有这个文件树:
`-- src
`-- model
|-- a4
| `-- public
| |-- css
| |-- img
| `-- js
|-- posters
| `-- public
| |-- css
| |-- img
| `-- js
`-- prints
`-- public
|-- css
|-- img
`-- js
我想将文件复制到
src/model/**/public/img 到 dist/images/{1}/ 其中{1} 是文件夹名称(a4、海报、印刷品...动态文件夹也必然会发生变化),所以:
src/model/a4/public/img/file.png -> dist/images/a4/file.png
有没有办法用 grunt-contrib-copy 指定(可能是重命名功能?)还是我必须手动遍历文件?
现在这就是我所拥有的:
grunt.registerTask 'images-generate', ->
gruntCopyFiles.images = {
expand: true,
cwd: './src/model/',
src: ["**/public/img/*.png", "**/public/img/*.jpg"],
dest: "./dist/images/"
}
但这会将src/model/a4/public/img/file.png 复制到dist/images/a4/public/img/file.png,这不是我想要的。
有什么建议吗?谢谢!
【问题讨论】:
-
刚刚意识到我可能使用的是 grunt.file.expandMapping 而不是 grunt-contrib-copy。维护别人的项目很有趣。
-
你还有这个问题吗?
-
是的!只是想弄清楚技术。现在我正在使用重命名功能,但如果有更好/内置/更短的方法,我会接受。我对此表示怀疑!
-
好的,太好了。您能否将您当前对
rename的尝试添加到问题中,以使读者更清楚?
标签: gruntjs grunt-contrib-copy