Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow Compile Times on Heroku #1347

Closed
sunnyrjuneja opened this issue Mar 13, 2018 · 13 comments
Closed

Slow Compile Times on Heroku #1347

sunnyrjuneja opened this issue Mar 13, 2018 · 13 comments

Comments

@sunnyrjuneja
Copy link
Contributor

sunnyrjuneja commented Mar 13, 2018

This issue is an offshoot of #1319 (comment).

We're trying to debug why compile times are slow on Heroku. We are using https://github.com/sunnyrjuneja/wbspeedtest as a reproducible guide.

Reproduce steps:

  1. Git clone repo
  2. $ heroku create
  3. $ heroku buildpacks:set heroku/ruby
  4. $ heroku buildpacks:add --index 1 heroku/nodejs This is necessary getting webpack working.

An application with no webpacker but both buildpacks added. Using commit: sunnyrjuneja/wbspeedtest@db5fd72

Result: Pretty fast.

λ →  git push heroku master
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 522 bytes | 522.00 KiB/s, done.
Total 6 (delta 3), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 8.x...
remote:        Downloading and installing node 8.10.0...
remote:        Using default npm version: 5.6.0
remote:
remote: -----> Restoring cache
remote:        Skipping cache restore (not-found)
remote:
remote: -----> Building dependencies
remote:        Installing node modules (package.json)
remote:        up to date in 0.076s
remote:
remote: -----> Caching build
remote:        Clearing previous node cache
remote:        Saving 2 cacheDirectories (default):
remote:        - node_modules (nothing to cache)
remote:        - bower_components (nothing to cache)
remote:
remote: -----> Pruning devDependencies
remote:        Skipping because npm 5.6.0 sometimes fails when running 'npm prune' due to a known issue
remote:        https://github.com/npm/npm/issues/19356
remote:
remote:        You can silence this warning by updating to at least npm 5.7.1 in your package.json
remote:        https://devcenter.heroku.com/articles/nodejs-support#specifying-an-npm-version
remote:
remote: -----> Build succeeded!
remote:  !     This app may not specify any way to start a node process
remote:        https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.3.4
remote: -----> Installing dependencies using bundler 1.15.2
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
remote:        Fetching gem metadata from https://rubygems.org/.........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Using rake 12.3.0
remote:        Using concurrent-ruby 1.0.5
remote:        Using minitest 5.11.3
remote:        Using thread_safe 0.3.6
remote:        Using builder 3.2.3
remote:        Using erubi 1.7.1
remote:        Using mini_portile2 2.3.0
remote:        Using crass 1.0.3
remote:        Using rack 2.0.4
remote:        Using nio4r 2.2.0
remote:        Using websocket-extensions 0.1.3
remote:        Using mini_mime 1.0.0
remote:        Using arel 8.0.0
remote:        Using bundler 1.15.2
remote:        Using coffee-script-source 1.12.2
remote:        Using execjs 2.7.0
remote:        Using method_source 0.9.0
remote:        Using thor 0.20.0
remote:        Using ffi 1.9.23
remote:        Using multi_json 1.13.1
remote:        Using pg 1.0.0
remote:        Using puma 3.11.3
remote:        Using rb-fsevent 0.10.3
remote:        Using tilt 2.0.8
remote:        Using turbolinks-source 5.1.0
remote:        Using i18n 0.9.5
remote:        Using tzinfo 1.2.5
remote:        Using nokogiri 1.8.2
remote:        Using rack-test 0.8.3
remote:        Using sprockets 3.7.1
remote:        Using websocket-driver 0.6.5
remote:        Using mail 2.7.0
remote:        Using coffee-script 2.4.1
remote:        Using uglifier 4.1.7
remote:        Using rb-inotify 0.9.10
remote:        Using turbolinks 5.1.0
remote:        Using activesupport 5.1.5
remote:        Using loofah 2.2.0
remote:        Using sass-listen 4.0.0
remote:        Using rails-dom-testing 2.0.3
remote:        Using globalid 0.4.1
remote:        Using activemodel 5.1.5
remote:        Using jbuilder 2.7.0
remote:        Using rails-html-sanitizer 1.0.3
remote:        Using sass 3.5.5
remote:        Using activejob 5.1.5
remote:        Using activerecord 5.1.5
remote:        Using actionview 5.1.5
remote:        Using actionpack 5.1.5
remote:        Using actioncable 5.1.5
remote:        Using actionmailer 5.1.5
remote:        Using railties 5.1.5
remote:        Using sprockets-rails 3.2.1
remote:        Using coffee-rails 4.2.2
remote:        Using rails 5.1.5
remote:        Using sass-rails 5.0.7
remote:        Bundle complete! 16 Gemfile dependencies, 56 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into ./vendor/bundle.
remote:        Bundle completed (3.02s)
remote:        Cleaning up the bundler cache.
remote:        Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
remote:        The latest bundler is 1.16.1, but you are currently running 1.15.2.
remote:        To update, run `gem install bundler`
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        Yarn executable was not detected in the system.
remote:        Download Yarn at https://yarnpkg.com/en/docs/install
remote:        Asset precompilation completed (1.64s)
remote:        Cleaning assets
remote:        Running: rake assets:clean
remote:
remote: ###### WARNING:
remote:        You have not declared a Ruby version in your Gemfile.
remote:        To set your Ruby version add this line to your Gemfile:
remote:        ruby '2.3.4'
remote:        # See https://devcenter.heroku.com/articles/ruby-versions for more information.
remote:
remote: ###### WARNING:
remote:        No Procfile detected, using the default web server.
remote:        We recommend explicitly declaring how to boot your server process via a Procfile.
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server
remote:
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> console, rake, web, worker
remote:
remote: -----> Compressing...
remote:        Done: 43.8M
remote: -----> Launching...
remote:        Released v6
remote:        https://cryptic-shore-39019.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/cryptic-shore-39019.git
   fc93341..db5fd72  master -> master

Using sunnyrjuneja/wbspeedtest@a503b21

Changes: Add webpacker
Details:

  • Added to Gemfile
  • bundle
  • bin/rails webpacker:install
  • Updated package.json to use recent node or uses old node which breaks webpacker
  • Update application.html.erb to include pack

Result:
Compile takes 26 seconds (with no additional deps)

Counting objects: 27, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (25/25), done.
Writing objects: 100% (27/27), 59.15 KiB | 2.69 MiB/s, done.
Total 27 (delta 10), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  8.10.0
remote:        engines.npm (package.json):   unspecified (use default)
remote:        engines.yarn (package.json):  1.5.1
remote:
remote:        Resolving node version 8.10.0...
remote:        Downloading and installing node 8.10.0...
remote:        Using default npm version: 5.6.0
remote:        Resolving yarn version 1.5.1...
remote:        Downloading and installing yarn (1.5.1)...
remote:        Installed yarn 1.5.1
remote:
remote: -----> Restoring cache
remote:        Skipping cache restore (new-signature)
remote:
remote: -----> Building dependencies
remote:        Installing node modules (yarn.lock)
remote:        yarn install v1.5.1
remote:        [1/4] Resolving packages...
remote:        [2/4] Fetching packages...
remote:        info [email protected]: The platform "linux" is incompatible with this module.
remote:        info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        [3/4] Linking dependencies...
remote:        warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
remote:        warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
remote:        warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
remote:        [4/4] Building fresh packages...
remote:        Done in 19.73s.
remote:
remote: -----> Caching build
remote:        Clearing previous node cache
remote:        Saving 2 cacheDirectories (default):
remote:        - node_modules
remote:        - bower_components (nothing to cache)
remote:
remote: -----> Pruning devDependencies
remote:        yarn install v1.5.1
remote:        [1/4] Resolving packages...
remote:        [2/4] Fetching packages...
remote:        info [email protected]: The platform "linux" is incompatible with this module.
remote:        info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        [3/4] Linking dependencies...
remote:        warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
remote:        warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
remote:        warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
remote:        [4/4] Building fresh packages...
remote:        warning Ignored scripts due to flag.
remote:        Done in 7.14s.
remote:
remote: -----> Build succeeded!
remote:  !     This app may not specify any way to start a node process
remote:        https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type
remote:
remote:  !     Unmet dependencies don't fail yarn install but may cause runtime issues
remote:        https://github.com/npm/npm/issues/7494
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.3.4
remote: -----> Installing dependencies using bundler 1.15.2
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
remote:        Fetching gem metadata from https://rubygems.org/.........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Using rake 12.3.0
remote:        Using concurrent-ruby 1.0.5
remote:        Using minitest 5.11.3
remote:        Using thread_safe 0.3.6
remote:        Using builder 3.2.3
remote:        Using erubi 1.7.1
remote:        Using mini_portile2 2.3.0
remote:        Using crass 1.0.3
remote:        Using rack 2.0.4
remote:        Using nio4r 2.2.0
remote:        Using websocket-extensions 0.1.3
remote:        Using mini_mime 1.0.0
remote:        Using arel 8.0.0
remote:        Using bundler 1.15.2
remote:        Using coffee-script-source 1.12.2
remote:        Using execjs 2.7.0
remote:        Using method_source 0.9.0
remote:        Using thor 0.20.0
remote:        Using ffi 1.9.23
remote:        Using multi_json 1.13.1
remote:        Using pg 1.0.0
remote:        Using puma 3.11.3
remote:        Using rb-fsevent 0.10.3
remote:        Using tilt 2.0.8
remote:        Using turbolinks-source 5.1.0
remote:        Using i18n 0.9.5
remote:        Using tzinfo 1.2.5
remote:        Using nokogiri 1.8.2
remote:        Using websocket-driver 0.6.5
remote:        Using mail 2.7.0
remote:        Using rack-test 0.8.3
remote:        Fetching rack-proxy 0.6.4
remote:        Using sprockets 3.7.1
remote:        Using uglifier 4.1.7
remote:        Using coffee-script 2.4.1
remote:        Using rb-inotify 0.9.10
remote:        Using turbolinks 5.1.0
remote:        Using activesupport 5.1.5
remote:        Using loofah 2.2.0
remote:        Using sass-listen 4.0.0
remote:        Using rails-dom-testing 2.0.3
remote:        Using globalid 0.4.1
remote:        Using activemodel 5.1.5
remote:        Using jbuilder 2.7.0
remote:        Using rails-html-sanitizer 1.0.3
remote:        Using sass 3.5.5
remote:        Using activejob 5.1.5
remote:        Using actionview 5.1.5
remote:        Using activerecord 5.1.5
remote:        Using actionpack 5.1.5
remote:        Using actioncable 5.1.5
remote:        Using actionmailer 5.1.5
remote:        Using railties 5.1.5
remote:        Using sprockets-rails 3.2.1
remote:        Using coffee-rails 4.2.2
remote:        Using rails 5.1.5
remote:        Using sass-rails 5.0.7
remote:        Installing rack-proxy 0.6.4
remote:        Fetching webpacker 3.3.1
remote:        Installing webpacker 3.3.1
remote:        Bundle complete! 17 Gemfile dependencies, 58 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into ./vendor/bundle.
remote:        Bundle completed (3.06s)
remote:        Cleaning up the bundler cache.
remote:        Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
remote:        The latest bundler is 1.16.1, but you are currently running 1.15.2.
remote:        To update, run `gem install bundler`
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        yarn install v1.5.1
remote:        [1/5] Validating package.json...
remote:        [2/5] Resolving packages...
remote:        [3/5] Fetching packages...
remote:        info [email protected]: The platform "linux" is incompatible with this module.
remote:        info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        [4/5] Linking dependencies...
remote:        warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
remote:        warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
remote:        warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
remote:        [5/5] Building fresh packages...
remote:        Done in 19.80s.
remote:        I, [2018-03-13T20:05:04.982774 #750]  INFO -- : Writing /tmp/build_3b35cadf526d326f0f650471fe62146f/public/assets/express/lib/application-3b5664140e227a165c1e83e47e05276e515f95dfc821fc57ca1487d894dd5d71.js
remote:        I, [2018-03-13T20:05:04.983597 #750]  INFO -- : Writing /tmp/build_3b35cadf526d326f0f650471fe62146f/public/assets/express/lib/application-3b5664140e227a165c1e83e47e05276e515f95dfc821fc57ca1487d894dd5d71.js.gz
remote:        Webpacker is installed 🎉 🍰
remote:        Using /tmp/build_3b35cadf526d326f0f650471fe62146f/config/webpacker.yml file for setting up webpack paths
remote:        Compiling…
remote:        Compiled all packs in /tmp/build_3b35cadf526d326f0f650471fe62146f/public/packs
remote:        Asset precompilation completed (26.20s)
remote:        Cleaning assets
remote:        Running: rake assets:clean
remote:
remote: ###### WARNING:
remote:        You have not declared a Ruby version in your Gemfile.
remote:        To set your Ruby version add this line to your Gemfile:
remote:        ruby '2.3.4'
remote:        # See https://devcenter.heroku.com/articles/ruby-versions for more information.
remote:
remote: ###### WARNING:
remote:        No Procfile detected, using the default web server.
remote:        We recommend explicitly declaring how to boot your server process via a Procfile.
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server
remote:
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> console, rake, web, worker
remote:
remote: -----> Compressing...
remote:        Done: 64.3M
remote: -----> Launching...
remote:        Released v7
remote:        https://cryptic-shore-39019.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy.... done.
To https://git.heroku.com/cryptic-shore-39019.git
   db5fd72..a503b21  master -> master

Using sunnyrjuneja/wbspeedtest@8cc9a32

Changes: Add dependencies (fontawesome) and include in application.js

* yarn add @fortawesome/fontawesome
* yarn add @fortawesome/fontawesome-free-solid
* yarn add @fortawesome/fontawesome-free-regular
* yarn add @fortawesome/fontawesome-free-brands

Result:
Asset precompilation completed (119.01s) (Big jump)

emote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  8.10.0
remote:        engines.npm (package.json):   unspecified (use default)
remote:        engines.yarn (package.json):  1.5.1
remote:
remote:        Resolving node version 8.10.0...
remote:        Downloading and installing node 8.10.0...
remote:        Using default npm version: 5.6.0
remote:        Resolving yarn version 1.5.1...
remote:        Downloading and installing yarn (1.5.1)...
remote:        Installed yarn 1.5.1
remote:
remote: -----> Restoring cache
remote:        Loading 2 from cacheDirectories (default):
remote:        - node_modules
remote:        - bower_components (not cached - skipping)
remote:
remote: -----> Building dependencies
remote:        Installing node modules (yarn.lock)
remote:        yarn install v1.5.1
remote:        [1/4] Resolving packages...
remote:        [2/4] Fetching packages...
remote:        info [email protected]: The platform "linux" is incompatible with this module.
remote:        info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        [3/4] Linking dependencies...
remote:        warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
remote:        warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
remote:        warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
remote:        [4/4] Building fresh packages...
remote:        Done in 24.53s.
remote:
remote: -----> Caching build
remote:        Clearing previous node cache
remote:        Saving 2 cacheDirectories (default):
remote:        - node_modules
remote:        - bower_components (nothing to cache)
remote:
remote: -----> Pruning devDependencies
remote:        yarn install v1.5.1
remote:        [1/4] Resolving packages...
remote:        [2/4] Fetching packages...
remote:        info [email protected]: The platform "linux" is incompatible with this module.
remote:        info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        [3/4] Linking dependencies...
remote:        warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
remote:        warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
remote:        warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
remote:        [4/4] Building fresh packages...
remote:        warning Ignored scripts due to flag.
remote:        Done in 7.75s.
remote:
remote: -----> Build succeeded!
remote:  !     This app may not specify any way to start a node process
remote:        https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type
remote:
remote:  !     Unmet dependencies don't fail yarn install but may cause runtime issues
remote:        https://github.com/npm/npm/issues/7494
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.3.4
remote: -----> Installing dependencies using bundler 1.15.2
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
remote:        Fetching gem metadata from https://rubygems.org/.........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Using rake 12.3.0
remote:        Using concurrent-ruby 1.0.5
remote:        Using minitest 5.11.3
remote:        Using thread_safe 0.3.6
remote:        Using builder 3.2.3
remote:        Using erubi 1.7.1
remote:        Using mini_portile2 2.3.0
remote:        Using crass 1.0.3
remote:        Using rack 2.0.4
remote:        Using nio4r 2.2.0
remote:        Using websocket-extensions 0.1.3
remote:        Using mini_mime 1.0.0
remote:        Using arel 8.0.0
remote:        Using bundler 1.15.2
remote:        Using coffee-script-source 1.12.2
remote:        Using execjs 2.7.0
remote:        Using method_source 0.9.0
remote:        Using thor 0.20.0
remote:        Using ffi 1.9.23
remote:        Using multi_json 1.13.1
remote:        Using pg 1.0.0
remote:        Using puma 3.11.3
remote:        Using rb-fsevent 0.10.3
remote:        Using tilt 2.0.8
remote:        Using turbolinks-source 5.1.0
remote:        Using tzinfo 1.2.5
remote:        Using i18n 0.9.5
remote:        Using nokogiri 1.8.2
remote:        Using mail 2.7.0
remote:        Using websocket-driver 0.6.5
remote:        Using uglifier 4.1.7
remote:        Using coffee-script 2.4.1
remote:        Using rb-inotify 0.9.10
remote:        Using rack-test 0.8.3
remote:        Using rack-proxy 0.6.4
remote:        Using sprockets 3.7.1
remote:        Using turbolinks 5.1.0
remote:        Using activesupport 5.1.5
remote:        Using loofah 2.2.0
remote:        Using sass-listen 4.0.0
remote:        Using rails-dom-testing 2.0.3
remote:        Using globalid 0.4.1
remote:        Using activemodel 5.1.5
remote:        Using jbuilder 2.7.0
remote:        Using rails-html-sanitizer 1.0.3
remote:        Using sass 3.5.5
remote:        Using activerecord 5.1.5
remote:        Using actionview 5.1.5
remote:        Using activejob 5.1.5
remote:        Using actionpack 5.1.5
remote:        Using actioncable 5.1.5
remote:        Using actionmailer 5.1.5
remote:        Using railties 5.1.5
remote:        Using sprockets-rails 3.2.1
remote:        Using coffee-rails 4.2.2
remote:        Using rails 5.1.5
remote:        Using sass-rails 5.0.7
remote:        Using webpacker 3.3.1
remote:        Bundle complete! 17 Gemfile dependencies, 58 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into ./vendor/bundle.
remote:        Bundle completed (3.26s)
remote:        Cleaning up the bundler cache.
remote:        Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
remote:        The latest bundler is 1.16.1, but you are currently running 1.15.2.
remote:        To update, run `gem install bundler`
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        yarn install v1.5.1
remote:        [1/5] Validating package.json...
remote:        [2/5] Resolving packages...
remote:        [3/5] Fetching packages...
remote:        info [email protected]: The platform "linux" is incompatible with this module.
remote:        info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        [4/5] Linking dependencies...
remote:        warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
remote:        warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
remote:        warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
remote:        [5/5] Building fresh packages...
remote:        Done in 21.59s.
remote:        Webpacker is installed 🎉 🍰
remote:        Using /tmp/build_2091f1146855f860ea67bbe7cfc16362/config/webpacker.yml file for setting up webpack paths
remote:        Compiling…
remote:        Compiled all packs in /tmp/build_2091f1146855f860ea67bbe7cfc16362/public/packs
remote:        Asset precompilation completed (119.01s)
remote:        Cleaning assets
remote:        Running: rake assets:clean
remote:
remote: ###### WARNING:
remote:        You have not declared a Ruby version in your Gemfile.
remote:        To set your Ruby version add this line to your Gemfile:
remote:        ruby '2.3.4'
remote:        # See https://devcenter.heroku.com/articles/ruby-versions for more information.
remote:
remote: ###### WARNING:
remote:        No Procfile detected, using the default web server.
remote:        We recommend explicitly declaring how to boot your server process via a Procfile.
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server
remote:
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> console, rake, web, worker
remote:
remote: -----> Compressing...
remote:        Done: 66.7M
remote: -----> Launching...
remote:        Released v8
remote:        https://cryptic-shore-39019.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/cryptic-shore-39019.git
   a503b21..8cc9a32  master -> master

Add typescript sunnyrjuneja/wbspeedtest@aebad73

  • bin/rails webpacker:install:typescript
  • yarn add ts-loader@3
  • yarn add typescript
  • mv app/javascript/packs/hello_typescript.ts app/javascript/src/hello_typescript.ts

Result:
Asset precompilation completed (123.62s)

-----> Node.js app detected
-----> Creating runtime environment
       
       NPM_CONFIG_LOGLEVEL=error
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
-----> Installing binaries
       engines.node (package.json):  8.10.0
       engines.npm (package.json):   unspecified (use default)
       engines.yarn (package.json):  1.5.1
       
       Resolving node version 8.10.0...
       Downloading and installing node 8.10.0...
       Using default npm version: 5.6.0
       Resolving yarn version 1.5.1...
       Downloading and installing yarn (1.5.1)...
       Installed yarn 1.5.1
-----> Restoring cache
       Loading 2 from cacheDirectories (default):
       - node_modules
       - bower_components (not cached - skipping)
-----> Building dependencies
       Installing node modules (yarn.lock)
       yarn install v1.5.1
       [1/4] Resolving packages...
       success Already up-to-date.
       Done in 1.21s.
-----> Caching build
       Clearing previous node cache
       Saving 2 cacheDirectories (default):
       - node_modules
       - bower_components (nothing to cache)
-----> Pruning devDependencies
       yarn install v1.5.1
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       info [email protected]: The platform "linux" is incompatible with this module.
       info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
       [3/4] Linking dependencies...
       warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
       warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
       warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
       [4/4] Building fresh packages...
       warning Ignored scripts due to flag.
       Done in 20.07s.
-----> Build succeeded!
 !     This app may not specify any way to start a node process
       https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type
 !     Unmet dependencies don't fail yarn install but may cause runtime issues
       https://github.com/npm/npm/issues/7494
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.3.4
-----> Installing dependencies using bundler 1.15.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
       Fetching gem metadata from https://rubygems.org/.........
       Fetching version metadata from https://rubygems.org/..
       Fetching dependency metadata from https://rubygems.org/.
       Using rake 12.3.0
       Using concurrent-ruby 1.0.5
       Using minitest 5.11.3
       Using thread_safe 0.3.6
       Using builder 3.2.3
       Using erubi 1.7.1
       Using mini_portile2 2.3.0
       Using crass 1.0.3
       Using rack 2.0.4
       Using nio4r 2.2.0
       Using websocket-extensions 0.1.3
       Using mini_mime 1.0.0
       Using arel 8.0.0
       Using bundler 1.15.2
       Using coffee-script-source 1.12.2
       Using execjs 2.7.0
       Using thor 0.20.0
       Using ffi 1.9.23
       Using multi_json 1.13.1
       Using pg 1.0.0
       Using puma 3.11.3
       Using method_source 0.9.0
       Using rb-fsevent 0.10.3
       Using tilt 2.0.8
       Using turbolinks-source 5.1.0
       Using i18n 0.9.5
       Using nokogiri 1.8.2
       Using tzinfo 1.2.5
       Using websocket-driver 0.6.5
       Using mail 2.7.0
       Using rack-test 0.8.3
       Using rack-proxy 0.6.4
       Using sprockets 3.7.1
       Using coffee-script 2.4.1
       Using uglifier 4.1.7
       Using rb-inotify 0.9.10
       Using turbolinks 5.1.0
       Using loofah 2.2.0
       Using activesupport 5.1.5
       Using sass-listen 4.0.0
       Using rails-dom-testing 2.0.3
       Using globalid 0.4.1
       Using activemodel 5.1.5
       Using jbuilder 2.7.0
       Using sass 3.5.5
       Using rails-html-sanitizer 1.0.3
       Using activejob 5.1.5
       Using actionview 5.1.5
       Using activerecord 5.1.5
       Using actionpack 5.1.5
       Using actioncable 5.1.5
       Using actionmailer 5.1.5
       Using railties 5.1.5
       Using sprockets-rails 3.2.1
       Using coffee-rails 4.2.2
       Using rails 5.1.5
       Using sass-rails 5.0.7
       Using webpacker 3.3.1
       Bundle complete! 17 Gemfile dependencies, 58 gems now installed.
       Gems in the groups development and test were not installed.
       Bundled gems are installed into ./vendor/bundle.
       Bundle completed (2.97s)
       Cleaning up the bundler cache.
       Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
       The latest bundler is 1.16.1, but you are currently running 1.15.2.
       To update, run `gem install bundler`
-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       yarn install v1.5.1
       [1/5] Validating package.json...
       [2/5] Resolving packages...
       [3/5] Fetching packages...
       info [email protected]: The platform "linux" is incompatible with this module.
       info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
       [4/5] Linking dependencies...
       warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
       warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
       warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
       [5/5] Building fresh packages...
       Done in 21.72s.
       Webpacker is installed 🎉 🍰
       Using /tmp/build_fc2bc630f1331613325f792acf9bc04e/config/webpacker.yml file for setting up webpack paths
       Compiling…
       Compiled all packs in /tmp/build_fc2bc630f1331613325f792acf9bc04e/public/packs
       Asset precompilation completed (123.62s)
       Cleaning assets
       Running: rake assets:clean
###### WARNING:
       You have not declared a Ruby version in your Gemfile.
       To set your Ruby version add this line to your Gemfile:
       ruby '2.3.4'
       # See https://devcenter.heroku.com/articles/ruby-versions for more information.
###### WARNING:
       No Procfile detected, using the default web server.
       We recommend explicitly declaring how to boot your server process via a Procfile.
       https://devcenter.heroku.com/articles/ruby-default-web-server
-----> Discovering process types
       Procfile declares types     -> (none)
       Default types for buildpack -> console, rake, web, worker
-----> Compressing...
       Done: 72.6M
-----> Launching...
       Released v10
       https://cryptic-shore-39019.herokuapp.com/ deployed to Heroku
@sunnyrjuneja
Copy link
Contributor Author

@gauravtiwari Hey, this is still a WIP. The only thing I've noticed for sure is that adding font-awesome jumps the precompile speed a lot from (26s with no deps to 119 sec). I'm going to keep experimenting when I have a bit more time because I'm in the 400 second mark with a marginally more complicated file. Don't worry about this issue as of now.

@rossta
Copy link
Member

rossta commented Mar 13, 2018

What size dyno(s) are you deploying? I'm assuming your dynos are hitting up against memory limits; webpack will certainly eat up a lot of memory depending on a number of factors like bundle size, plugins and loaders in use, etc.

@sunnyrjuneja
Copy link
Contributor Author

@rossta For the sake of this test, I'm using dynos with 512 mb. I'm using a marginally more complicated application.js (fontawesome free vs pro, maybe 50 lines of javascript) and it's taking over 6 minutes.

@sunnyrjuneja
Copy link
Contributor Author

@gauravtiwari Okay, I did some more experiments and found when I removed fontawesome pro from my repo, I was able to drop the compile time from ~400 seconds to ~40 seconds.

Font Awesome Pro has more icons as well an additional library, fontawesome light (listed above is solid, normal and brands). I guess the additional library + more icons is adding about another 200 seconds.

I don't know if this an issue with webpacker + fonts, webpacker + node_modules or webpacker + fontawesome.

Hopefully, this helps enough for reproducability. If there's anything else I can do to help, let me know. I'm going to email the maintainers of fontawesome and let them know.

@sunnyrjuneja
Copy link
Contributor Author

I'm going to close this issue since I believe my problem can be isolated to FontAwesome. Based on the comments on the issue, it does not seem they have a solution in mind. I will wait for a gem to (hopefully) be released or maybe upgrading to Webpacker 4 will help.

@benbonnet
Copy link

benbonnet commented May 5, 2018

@sunnyrjuneja google brought me there; not exactly related, but as heroku provides caching for node_modules, how one would benefit from this while running webpacker ?

So far, I've witnessed that, when deploying on heroku :

  • adding the nodejs buildpack ends with two yarn commands being run (one in rails/webpacker, one because heroku nodejs buildpacks detect a package.json)
  • using only the ruby buildpack, one yarn command is run, but nothing gets cached, a full yarn install will be run on every deploys

Thx alot if you have any help on this one

@sunnyrjuneja
Copy link
Contributor Author

@benbonnet as far as I know there's no way to do so and heroku is aware heroku/heroku-buildpack-ruby#654

@benbonnet
Copy link

More or less trying to make sure nothing was wrong in my current setup
Thx alot for pointing this one out!

@sunnyrjuneja
Copy link
Contributor Author

@benbonnet no problem have a nice weekend

ericboehs added a commit to ericboehs/heroku-buildpack-ruby that referenced this issue Sep 2, 2018
 ## 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
@ericboehs
Copy link
Contributor

@benbonnet I too had this issue and I believe the only thing I changed was setting YARN_PRODUCTION to true. It does run yarn install twice stioll (once per buildpack) but each only take 2 seconds.

@vill
Copy link

vill commented Sep 3, 2018

I have the same issue with the new package @fortawesome/free-solid-svg-icons. Sometimes the compilation was more than 200 seconds.

node - v8.4.0
@fortawesome/fontawesome-svg-core - v1.2.4
@fortawesome/free-solid-svg-icons - v5.3.1
@rails/webpacker - v3.5

The following helps me solve this issue:

  1. If you only include the necessary icons

    Slowly:

    import { library, dom } from '@fortawesome/fontawesome-svg-core'
    import { faSpinner } from '@fortawesome/free-solid-svg-icons'

    Faster:

    import { library, dom } from '@fortawesome/fontawesome-svg-core'
    import { faSpinner } from '@fortawesome/free-solid-svg-icons/faSpinner'

    Faster:

    // config/webpack/environment.js
    
    const { environment } = require('@rails/webpacker')
    
    if (environment.plugins.getIndex('UglifyJs') !== -1) {
      environment.plugins.get('UglifyJs').options.uglifyOptions.compress.collapse_vars = false
    }
    
    module.exports = environment
    import { library, dom } from '@fortawesome/fontawesome-svg-core'
    import { faSpinner } from '@fortawesome/free-solid-svg-icons'
  2. When you include all styles

    Slowly:

    import { library, dom } from '@fortawesome/fontawesome-svg-core'
    import { fas } from '@fortawesome/free-solid-svg-icons'

    Faster:

    // config/webpack/environment.js
    
    const { environment } = require('@rails/webpacker')
    
    if (environment.plugins.getIndex('UglifyJs') !== -1) {
      environment.plugins.get('UglifyJs').options.uglifyOptions.compress.collapse_vars = false
    }
    
    module.exports = environment
    import { library, dom } from '@fortawesome/fontawesome-svg-core'
    import { fas } from '@fortawesome/free-solid-svg-icons'

@stevenharman
Copy link
Contributor

Turning off the collapse_vars configuration dropped by compilation a ton. On my local machine (a 2017 MBP, 3.1GHz i7, 16GB RAM) it was taking around 500s (8.3 minutes). Turning off that setting dropped it to around 40s!

I hate to randomly turn things off like this, but when deploying to Heroku the build times are even slower (around 10 min, but twice b/c of the Rails + Node build pack issues e.g. heroku/heroku-buildpack-ruby#654).

Does anyone know why this is happening? Or if there's a better fix than a random configuration change?

@sunnyrjuneja
Copy link
Contributor Author

Our fix was to use FontAwesome's precompiled builds. You can still use package.json and add to Webpacker:

import "@fortawesome/fontawesome-free/js/all"
import "@fortawesome/fontawesome-pro/js/all"

qrush pushed a commit to chatterbugapp/heroku-buildpack-ruby that referenced this issue May 17, 2019
 ## 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
ankane pushed a commit to ankane/heroku-buildpack-ruby that referenced this issue May 25, 2019
 ## 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]>
timm-oh pushed a commit to howler/heroku-buildpack-ruby that referenced this issue Jul 9, 2019
 ## 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]>
timm-oh pushed a commit to howler/heroku-buildpack-ruby that referenced this issue Jan 24, 2020
 ## 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]>
joshkinabrew pushed a commit to KingmanAg/heroku-buildpack-ruby that referenced this issue Oct 21, 2020
 ## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants