Smoothing the file tree when using the Copy Copy task

Not sure if I missed something, but I have the following grunt setting for grunt-contrib-copy tasks.

copy: { build: { files: { "server-dist/": "server/**/*.!(coffee)", "client-dist/": "client/**/*.!(coffee)" } } } 

The client-dist copies as I expect it to recursively work through the file tree, but the server-dist will all subfolders be smoothed to the base folder. Any idea why this is happening? Here i / o

 server/ views/ errors/ 404.jade layouts/ base.jade 

becomes

 server/ errors/ layouts/ base.jade 

the views folder is completely blown out. One more thing ... when I delete! (Coffee), this works, but I need to exclude coffee files, since I have work with the grunt-coffee watch function.

+4
source share
2 answers

Apparently, the grunt-contrib-copy task has complex logic that tries to automatically determine the base directory for copying the source files (see related problem )

The solution is to explicitly specify the basePath parameter:

 copy: { build: { files: { "server-dist/": "server/**/*!(.coffee)" }, options: { basePath: 'server' // base directory in the source path } } } 

PS I'm not sure why deleting !(.coffee) changes the behavior for you. I tried the same thing on my local machine and got the same results when specifying "server/**/*" instead of "server/**/*.!(coffee)" (i.e. the views folder is skipped)

+2
source

Comment on zacks comments:

 copy: { mytask: { files: [ {expand:true, cwd:'dev-js/abc/', dest:'js/test/', src:['def.js']} ] } } 

This copies the ./dev-js/abc/def.js file to ./js/test/def.js - at least in my version 0.4.1. The Zacks comment and the included link were very helpful, especially the fact that basePath been replaced.

+8
source

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


All Articles