Search code examples
npmcopycross-platformnpm-scriptsmultiplatform

Recursively copy files cross-platform via npm script


We have within a package.json build script a copy command (no we cant quickly change that).

Is there any solution we can make this work multiplatform with the same syntax easily?

I looked in several npm copy packages, but they don't transpile from windows to unix paths.

We basically need something like:

"build": "doStuff && cp -r ../folder/ /dist/"

working for windows.

Any ideas?


Solution

  • For a cross-platform solution consider utilizing the shx package.

    1. Firstly cd to your project directory and run the following command to install it:

      npm i -D shx
      
    2. Then redefine your build script in the scripts section of your package.json as follows:

      "scripts": {
         "build": "doStuff && shx cp -r ../folder/ ./dist/"
      }