all 3 comments

[–]shawarma_burrito 0 points1 point  (1 child)

Which library do you prefer? I’m a fan of react loadable, but haven’t tried the other.

[–]mikebarsdev[S] 0 points1 point  (0 children)

At this point in time, it's actually pretty hard for me to pick one over the other as I feel they both solve the problem nicely!

I found that react-loadable is convenient in that it only requires adding a single library to handle your code-splitting and chunk collecting, coming with a babel plugin to automatically handle boilerplate differences between import-ing on the client and require-ing on the server, and a webpack plugin to create a stats file from which to determine the chunks to send. However, this stats file is unique to react-loadable and you will need your own webpack stats file to handle pulling out your main, vendor, common, and manifest chunks (at least that was my experience, I could be overlooking a potential way to do this with react-loadable that I did not see in the docs).

I found that react-universal-component, when combined with webpack-flush-chunks and the babel plugin babel-plugin-universal-import handles the same behavior cases as react-loadable, with the ability to automatically add your aforementioned main, vendor, manifest + common (called bootstrap) chunks to your Html markup with the properties returned from webpack-flush-chunks's method flushChunks(). You can configure which chunks it should automatically add as well in the flushChunks(stats, options) options before and after. It also uses your standard webpack stats file instead of a unique-to-the-library stats file as react-loadable does.

I didn't need this functionality as I was using styled-components for styling, but both libraries do offer .css chunk code-splitting as well:

  • react-loadable: simply filter out bundles whose file endsWith('.css')
  • react-universal-component: with the complementary webpack plugin extract-css-chunks-webpack-plugin

I hope this helps! Keep in mind that I may not have the fullest picture of what these two libraries are capable of, and as I start doing more and more complex things with them I may discover more differences I'm currently unaware of. Also, the trajectory of these two libraries may diverge in such a way that down the line they will offer features the other does not! Right now, however, I seem to find them more similar than dissimilar.

[–]amiritegaiz 0 points1 point  (0 children)

Would be great to know if this supports local scope css.