Search code examples
npmcreate-react-appfile-copying

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.


Solution

  • 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.