npm script, copy package.json to dist when bundling

If you're running on windows use the following command:

"copy": "copy \"package.json\" \"dist\" && copy \"README.md\" \"dist\" && copy \".npmrc\" \"dist\""

copy instead of cp. Don't forget to use "" for each path (escape them with \ within the quoted command). and if you need to define a long path, don't use / (slashes) but \ (backslashes)

like:

copy "devices\\VS-88UT\\index.html" "devices\\VS-88UT\\dist"

Also, if you prefere ther is a nice plugin to run bash command before and after each build


The syntax should work (and seems to, looking at your comments). I would suggest splitting your npm scripts across multiple points, though:

{
  "bundle": "NODE_ENV=production webpack --output-file bundledFile.js",
  "copy": "cp package.json dist/ && cp README.md dist/ && cp .npmrc dist/",
  "build": "npm run bundle && npm run copy"
}

In order to be cross-platform compatible (cp is not typically available on windows), I would also suggest adding a build file somewhere such as ./tools/copy-distrubution-files.js which would make use of fs to copy the necessary files, then call it in the npm scripts with node ./tools/copy-distribution-files.js. That will be (mostly) platform independent (you still have to assume that node is available as the nodejs executable, but that seems fairly reasonable to me).


The quickest way for me was to reference powershell in a package.json script like this:

"copyFile": "@powershell copy './source/package.json' './deploy'",