23

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?

RobC
  • 22,977
  • 20
  • 73
  • 80
fredalex
  • 433
  • 5
  • 15
  • 4
    Why isn't this among the most searched-for npm scripts question?! I searched for it over and over. I started writing up my own question, and then this finally percolated to the top five questions in the suggested list. – Brandon Mar 06 '20 at 13:59

1 Answers1

34

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/"
    }
    
RobC
  • 22,977
  • 20
  • 73
  • 80