Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy files with npm copyfiles to another directory

I want that in the end of my build script, the build folder will be copy to another location, so I tried using copy-files-package -

"build": "react-scripts build && copyfiles build/*. out",

I was not able to figure out how to copy the entire build folder to another location, trying to specify the location like C:/someLocaion/build2 will result in the console showing SomeLocaion/build2.

like image 742
Itsik Mauyhas Avatar asked Sep 19 '25 07:09

Itsik Mauyhas


1 Answers

copyfiles didn't work for me on Windows. I've replaced it with shx, which is cross-platform. I'd also suggest to move the copy step to a separate script called postbuild (which will be ran automatically after the build script) for better separation of concerns:

"build": "react-scripts build",
"postbuild": "shx rm -rf out && shx cp -r build out",

Notice that I'm also wiping the target directory before copying the build artifacts there to avoid any leftovers from the previous build.

like image 77
yurloc Avatar answered Sep 21 '25 05:09

yurloc