Skip to content

Instantly share code, notes, and snippets.

@igrek8
Created July 6, 2022 08:49
Show Gist options
  • Save igrek8/f104830f4ad7aa7d1cd6620a5763807a to your computer and use it in GitHub Desktop.
Save igrek8/f104830f4ad7aa7d1cd6620a5763807a to your computer and use it in GitHub Desktop.
copy production node_modules
set -eo pipefail
node_modules=$(pwd)/node_modules
output="$1/nodejs/node_modules"
list=($(npm list --production --all --parseable))
mkdir -p $output
for item in "${list[@]}"; do
path=$(realpath --relative-to="$node_modules" "$item")
[[ "${path}" == ".." ]] && continue
mkdir -p "$output/$path"
cp -r -d "$item" "$output/$path"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment