Skip to content

Commit

Permalink
Cache node modules and meteor build
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnowack committed Dec 5, 2018
1 parent c985dde commit e41b8f7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,14 @@ echo "-----> and npm: `$METEOR_NPM --version`"
# If we use npm on root, run npm install. Don't use `--production` here, as we
# may need devDependencies (e.g. webpack) in order to build the meteor app.
if [ -e "$APP_SOURCE_DIR"/package.json ]; then
mkdir -p "$CACHE_DIR/meteor-dev-modules"
if [ -n "$(ls -A $CACHE_DIR/meteor-dev-modules)" ]; then
echo "-----> Reusing development node_modules cache"
mkdir -p "$APP_SOURCE_DIR/node_modules"
mv "$CACHE_DIR/meteor-dev-modules/*" "$APP_SOURCE_DIR/node_modules"
fi
$METEOR_NPM install
cp -a "$APP_SOURCE_DIR/node_modules/*" "$CACHE_DIR/meteor-dev-modules/"
fi

# Related to https://github.com/meteor/meteor/issues/2796 and
Expand All @@ -193,6 +200,12 @@ echo "-----> Building Meteor app with ROOT_URL: $ROOT_URL"
BUNDLE_DEST=`mktemp -d "$BUILDPACK_DIR/build-XXXX"`

# The actual invocation of `meteor build`!
mkdir -p "$CACHE_DIR/meteor-build"
rm -rf "$APP_SOURCE_DIR"/.meteor/local
if [ -n "$(ls -A $CACHE_DIR/meteor-build)" ]; then
echo "-----> Reusing meteor build cache"
fi
ln -s "$CACHE_DIR/meteor-build" "$APP_SOURCE_DIR/.meteor/local"
METEOR build $BUILD_OPTIONS --server $ROOT_URL $SERVER_ONLY_FLAG --directory $BUNDLE_DEST

echo "-----> Moving built slug to $COMPILE_DIR/app"
Expand All @@ -203,7 +216,14 @@ rmdir $BUNDLE_DEST
echo "-----> Installing npm production dependencies on built slug"
if [ -e "$COMPILE_DIR"/app/programs/server/package.json ]; then
cd "$COMPILE_DIR"/app/programs/server
mkdir -p "$CACHE_DIR/meteor-prod-modules"
if [ -n "$(ls -A $CACHE_DIR/meteor-prod-modules)" ]; then
echo "-----> Reusing production node_modules cache"
fi
mv "$CACHE_DIR/meteor-prod-modules/*" "$COMPILE_DIR/app/programs/server/node_modules" &> /dev/null || true
rm -rf "$CACHE_DIR/meteor-prod-modules"
$METEOR_NPM install --production
cp -R "$COMPILE_DIR/app/programs/server/node_modules" "$CACHE_DIR/meteor-prod-modules"
cd "$APP_SOURCE_DIR"
fi

Expand Down Expand Up @@ -235,5 +255,5 @@ done
#
if [ -n "${BUILDPACK_CLEAR_CACHE+1}" ]; then
echo "-----> Clearing cache dir."
rm -rf $METEOR_DIR
rm -rf "$CACHE_DIR/*"
fi

0 comments on commit e41b8f7

Please sign in to comment.