Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache Webpacker builds between deploys
## Goal Facilitate Webpacker's existing caching to skip running Webpack on builds where no changes are made. ## Approach Cache Webpacker's default pack output and cache paths between deploys. ## Context Currently all deploys using Webpacker will recompile on every deploy even if there are no files changed. This is because the digest file and packs directory is not cached between deploys. By default, Webpacker stores a cache digest in `tmp/cache/webpacker` and its packs in `public/packs`. Webpacker iterates over the watched paths to compute a digest based on the mtime of the files. If none of the files have changed and the packs directory is in place, running Webpack is skipped, saving a lot of time (e.g. my company's Rails app takes 8 minutes to run webpack). ## Caveats The environment variable `CI` needs to be set as the mtime does not seem to be preserved correctly across deploys. If `ENV['CI']` is set, Webpacker will use the file contents to compute the cache digest file instead of the files' mtime. I'm not familiar enough with the Heroku infrastructure to understand why the mtime isn't being preserved. I did notice that `cp`ing is done via `-a` which preserves timestamps via `--preserve=all` but that doesn't seem to be enough. ## Further Notes This could technically be solved without modifying either Webpacker or the Heroku build pack but I thought this would be the best place as it fixes all existing configurations provided they used the default settings. This would also make the default "just work" instead of requiring end users to configure their Rails apps specifically for Heroku. I didn't mean for this pull request to be the canonical place to fix this issue but merely an issue report with a solution attached. ## Related * rails/webpacker#1347 Signed-off-by: Andrew Kane <[email protected]>
- Loading branch information