Skip to content

Instantly share code, notes, and snippets.

@miraculixx
Created April 29, 2026 12:42
Show Gist options
  • Select an option

  • Save miraculixx/fe886d0f7d32ae9fefe0b0a86337e86d to your computer and use it in GitHub Desktop.

Select an option

Save miraculixx/fe886d0f7d32ae9fefe0b0a86337e86d to your computer and use it in GitHub Desktop.
copyjs.sh - copy distribution files from node_modules
#!/bin/bash
# copy-dist-deps.sh - Pure bash dist file copier
# using perplexity.ai
# I wrote this because there is no good solutio as of 2026(sic!)
# to simply install packages and then extract just the files you
# actually need in production
#
# ref. https://www.perplexity.ai/search/a7ed838d-9bd5-4f5f-9e77-8d1456d86473#22
SRC=myapp
TARGET="${1:-$SRC/static/$SRC/js/libs}"
mkdir -p "$TARGET"
echo "📦 Copying dist files from node_modules to $TARGET..."
# JS files from common dist locations
find $SRC/node_modules -name "*min.js" \
-exec bash -c '
src="$1"
pkg=$(echo "$src" | sed "s|.*/node_modules/\([^/]*\)/.*|\1|" | head -1)
fname=$(basename "$src")
dest="$2/$pkg/$fname"
mkdir -p "$(dirname "$dest")"
cp "$src" "$dest"
echo "➤ $pkg/$fname"
' _ {} "$TARGET" \;
# CSS files
find node_modules -name "*.css" \
-exec bash -c '
src="$1" pkg=$(basename "$(dirname "$(dirname "$src")")")
pkg=$(echo "$src" | sed "s|.*/node_modules/\([^/]*\)/.*|\1|" | head -1)
fname=$(basename "$src")
dest="$2/$pkg/$fname" mkdir -p "$(dirname "$dest")" cp "$src" "$dest"
' _ {} "$TARGET" 2>/dev/null || true
echo "$(find "$TARGET" | wc -l) files copied ($(du -sh "$TARGET"))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment