Skip to content

Instantly share code, notes, and snippets.

@whollacsek
Created March 23, 2017 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whollacsek/ef871636f271a4cd1656f6a7435d3cfd to your computer and use it in GitHub Desktop.
Save whollacsek/ef871636f271a4cd1656f6a7435d3cfd to your computer and use it in GitHub Desktop.
#!/bin/bash -e
# by @stretchkennedy: https://github.com/zeit/next.js/issues/70#issuecomment-271150845
ADDR=${ADDR:-'http://localhost:3000'}
DEST=${DEST:-'dist'}
PAGES_DIR=${PAGES_DIR:-'pages'}
echo "starting server..."
next build
next start 2>&1 > /dev/null &
echo "downloading static assets..."
wget --html-extension \
--recursive \
--convert-links \
--page-requisites \
--no-parent \
--directory-prefix "$DEST" \
--no-host-directories \
--restrict-file-names=unix \
--quiet \
--retry-connrefused \
--waitretry 2 \
--tries 5 \
-i <(find "$PAGES_DIR" -type f | \
sed "s:^$PAGES_DIR\(.*\)\.js\$:\1:g" | \
sed 's:/index$:/:g' | \
sed "s,\(.*\),$ADDR\1,g")
echo "closing server..."
pkill -INT -g $$ node
wait
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment