Presentation PDF - A-Way-To-Upgrade-To-React
To be frank, I had never heard about React.js
till my friend Revath S Kumar, visited me back in December, 2015. He had given an intro to it, then I tried out few code and liked the way it worked, though I didn't understand it much, I liked the props
and state
;) & it was v0.14.x
then.
I wanted to start with the work on the real project and decided to start with a module which was in pipeline to develop.
Being a traditional developer started writing the script under assets/js
directory.
I had started with including the jsx
files directly in the browser by loading the react & react-dom
CDN files.
NOOO! I had failed, when I wanted to add new packages. I started getting pain in *** :)
I told my friend the way I worked, he has asked me to change my approach by using webpack.
Well, I had gone through the docs and started making the config file to bundle it.
Again another NOOO! I had to try & try & try & try (...) to make it working atleast.
As it was the only page which was using React.js
, I had included the bundled file directly.
NOOO! I had faced the caching issues when I update the source code.
I had spent some more time on webpack
and came across hashing the files.
Yes it does.
I had to spend time again on finding out the solution for this as well. Came across the plugin assets-webpack-plugin and did a work around with that.
It contains the latest hashed file names - JS & CSS in a json file which is specified in the webpack
config.
Then I applied own logics to load the related JS & CSS files on the page, by hard coding the entry points in server coding, reading the json file for required entry point & loading those required CSS & JS into the page. Also set a flag on server side to load other required JS & CSS on other pages.
With this logic, I could upgrade other modules on our website to React Magic
In couple of months React.js
released its v15.x.x
and I thought I must do an upgrade and started working on it. I also had to upgrade the webpack
to v2.x.x
. The configuration changed a lot.
You can start with React 16
& webpack
v4.x.x
for bundling.