28

We are using React on Rails within our Rails app. When we deploy, asset pre-compilation takes ~20 minutes.

Based on the deploy logs, it appears as though most of this time is spent pre-compiling a 3.3MB javascript file. That file "app.js" concatenates two files which are generated by webpack:

# app.js

//= require vendor-bundle (250KB)
//= require app-bundle  (3.3MB)

Should we just come to expect long pre-compile times given the size of app-bundle? Or, can we improve things?

As an additional note, we tried directly compiling app-bundle, instead of requiring it through app.js, and it took the same amount of time.

UPDATE:

We ended up breaking out the client code into a separate create-react-app project, which connects to our Rails app via API. The complexity of our devops and deployment pipeline was greatly reduced -- short of really digging into this error.

Ben
  • 15,010
  • 11
  • 58
  • 90
  • 1
    20 minutes is absurdly long for a 3mb js file. are you possibly precompiling stuff in a node_modules folder by accident? – azium Apr 07 '18 at 21:19
  • 1
    It's definitely the app.js file that is taking 20 minutes. We removed it and the entire deploy took 3 minutes. – Ben Apr 07 '18 at 21:36
  • 2
    something is going majorly wrong then. definitely not expected behaviour. maybe drop the asset-pipeline and just use the optimizations that are available for webpack – azium Apr 07 '18 at 22:02
  • 2
    Sounds like you need some debugging help. I'm the creator of React on Rails. We have a support plan to help you. See http://www.shakacode.com/work/shakacode-pro-support.pdf – justingordon Apr 08 '18 at 05:25
  • 7
    Hard to comment this way, it requires debugging and without a reproducible sample it is difficult to say what could be wrong – Tarun Lalwani Apr 10 '18 at 18:05
  • We use webpack to bundle our react (1.3MB after bundle) and then copy that into the rails assets/javascript folder and use it there. Takes about 15sec to bundle, so whatever is going on is not correct. (Our setup is unique, as we are also using angular) How long does it take with webpack? Can you call the bundle from app.js (essentially a simplified version of what we do). – alex Apr 13 '18 at 06:30
  • What version of webpack are you running? How long has this been going on? – kingsfoil Apr 15 '18 at 23:36
  • Can you also check if there is anything downloaded ? – Soleil Apr 16 '18 at 17:30
  • 1
    Please attach your `webpack.vendor.config.js` and `webpack.app.config.js` files – ErvalhouS Apr 16 '18 at 19:22
  • 1
    @Ben, without additional info, your bounty is about to go down the drain – Tarun Lalwani Apr 17 '18 at 11:43

1 Answers1

2

You should definitely integrate webpack using the webpacker gem (https://github.com/rails/webpacker)

You can also try and check Bootsnap gem of Shopify (https://github.com/Shopify/bootsnap)

Oz Ben-David
  • 1,589
  • 1
  • 16
  • 26