xyu / heroku-wp

WordPress on Heroku
MIT License
869 stars 279 forks source link

Ignoring files unneeded for building slug #95

Open toddheslin opened 7 years ago

toddheslin commented 7 years ago

I've noticed the the slug can sometimes take a huge time to compile if the theme is using NPM modules. I'm personally using FoundationPress on my site and the NPM modules folder (including dev dependencies) is over 200MB.

I also don't want all of the wordpress themes included in the composer install (back to twentyeleven!)

Therefore in support/app_slug_compile.sh I have changed:

# Recursively copy files build final web dir
cp -R vendor/WordPress/WordPress/* tmp/public.building
cp -R public/* tmp/public.building

to

# Recursively copy files build final web dir
rsync -r --exclude=wp-content/themes vendor/WordPress/WordPress/* tmp/public.building
rsync -r --exclude=wp-content/themes/ridehacks-foundation/node_modules public/* tmp/public.building

Haven't noted any bugs here, and not sure if the rsync can be optimised. However just leaving this as an enhancement for peoples to try out.

Thanks for this awesome repo @xyu

Tailzip commented 7 years ago

I wanted to get rid of WP default themes too! So, I updated support/app_slug_compile.sh, now it looks like this:

# ...

# Remove files to slim down slug if we're on Heroku
if [ ! -e .sluglocal ]
then
  rm -rf vendor/WordPress
  rm -rf public.built/wp-content/themes/twenty* # <- added this
  rm -rf public
fi

# ...

Also, regarding your huge theme folder, you can ignore files/folders added to the slug by adding them in .slugignorefile. Mine looks like this for example:

# Ignored Theme's Assets and Folders
**/node_modules/
**/package.json
**/.jshintrc
**/.jshintignore
**/gulpfile.js
**/ruleset.xml
**/.gitignore
**/bowerrc
**/.editorconfig

Hope this helps!

toddheslin commented 7 years ago

Thanks @Tailzip I totally forgot to look at the if block below! Seems like the most logical way to do it.

I was under the impression that the .slugignore is specific to Heroku and not the local Vagrant setup. Maybe @xyu can clarify and make a decision on the right way to ignore these. I think your solution is better, unless the reloader daemon starts copying files to Vagrant before the remove takes place, causing more issues.

Not sure what is going on under the hood for this sync function.

xyu commented 7 years ago

Yeah right now the rebuild script is pretty hacky, it should probably actually read .slugignore when building the public html dir seeing as that would make it more like production.