SlideShare a Scribd company logo
Building and Deploying React
Applications
Boris Nadion
boris@astrails.com
@borisnadion
@borisnadion
boris@astrails.com
astrails
http://astrails.com
2005
awesome web and mobile apps
building & deploying
building & deploying
facebookincubator/create-react-app
Create React apps with no build configuration.
npm install -g create-react-app
create-react-app my-app
cd my-app/
npm start
customize
like adding css preprocessors
yarn eject / npm eject
yarn eject / npm eject
not trivial
start from scratch
setup internals
Building and deploying React applications
environments
✓ development
✓ production
x test
package.json
"babel": { 

"presets": [ 

[ 

"es2015", 

{ 

"modules": false 

} 

], 

"react", 

"stage-0" 

], 

"plugins": [ 

"transform-runtime", 

"babel-plugin-transform-class-properties", 

"transform-object-rest-spread" 

], 

"env": { 

"production": { 

"plugins": [ 

"transform-react-inline-elements", 

"transform-react-constant-elements", 

"transform-react-remove-prop-types" 

] 

} 

} 

}, 

babel-plugin-transform-class-properties
class Bork { 

//Property initializer syntax 

instanceProperty = "bork"; 

boundFunction = () => { 

return this.instanceProperty; 

} 



//Static class properties 

static staticProperty = "babelIsCool"; 

static staticFunction = function() { 

return Bork.staticProperty; 

} 

}


let n = { x, y, ...z }; 

transform-object-rest-spread
transform-react-inline-elements
babelHelpers.jsx(Baz, { foo: "bar" }, "1");
const Hr = () => { return <hr className="hr" />; }; 



const _ref = <hr className="hr" />; 

const Hr = () => { 

return _ref; 

}; 

transform-react-inline-elements
Baz.propTypes = {…}
transform-react-remove-prop-types
“start":
"env NODE_ENV=development webpack-dev-server --progress --colors",
“build":
"rimraf dist &&
env NODE_ENV=production webpack --colors &&
cp ./dist/* ../public/assets/",
Building and deploying React applications
webpack config
webpack config
http://imgur.com/gallery/EnAmi
Building and deploying React applications
const ENV = process.env.NODE_ENV; 

const VALID_ENVIRONMENTS = ['development', 'production']; 



if (!VALID_ENVIRONMENTS.includes(ENV)) { 

throw new Error(`${ ENV } is not valid environment!`); 

} 

const DEVELOPMENT_CONFIG = require('./config/webpack.dev'); 

const PRODUCTION_CONFIG = require('./config/webpack.prod'); 



const config = { 

development: DEVELOPMENT_CONFIG, 

production: PRODUCTION_CONFIG 

}[ENV]; 





const COMMON_CONFIG = { … };

module.exports = webpackMerge.smart(COMMON_CONFIG, config); 

let’s look at the code
webpack.config.js + dev + prod
3 bundles
bundle.js
+ css
client.js
+ css
async.js
+ css
yarn start v0.24.4
$ env NODE_ENV=development webpack-dev-server --progress --colors
10% building modules 2/2 modules 0 active
Project is running at http://0.0.0.0:9001/
webpack output is served from http://localhost:9001/assets/
404s will fallback to /index.html
Hash: 9a91c0c826ebb4c40f2a
Version: webpack 2.6.1
Time: 6507ms
Asset Size Chunks Chunk Names
0.js 806 bytes 0 [emitted]
client.js 313 kB 1 [emitted] [big] client
vendor.js 1.45 MB 2 [emitted] [big] vendor
0.js.map 572 bytes 0 [emitted]
client.js.map 360 kB 1 [emitted] client
index.html 421 bytes [emitted]
webpack: Compiled successfully.
dev mode demo
hot reload, async load, eslint errors
//…
import { AppContainer } from 'react-hot-loader'; 



//…

const hotRender = () => { 

render( 

<AppContainer> 

<Application store={ store } /> 

</AppContainer>, 

document.getElementById('root') 

); 

}; 



hotRender(); 



module.hot.accept('components/Application', hotRender); 



hot reload
import asyncComponent from 'components/AsyncComponent'; 



const AsyncDashboard = asyncComponent(() => 

import('./Dashboard').then(module => module.default) 

); 



export default AsyncDashboard; 



async load
import React from 'react'; 



const asyncComponent = (getComponent) => 

class AsyncComponent extends React.Component { 

state = { Component: null }; 



componentWillMount() { 

if (!this.state.Component) { 

getComponent().then(Component => { 

this.setState({ Component }); 

}); 

} 

} 

render() { 

const { Component } = this.state; 

if (Component) { 

return <Component { ...this.props } />; 

} 

return null; 

} 

}; 



export default asyncComponent; 

async load
prod build
yarn build
yarn build v0.24.4
$ rimraf dist && env NODE_ENV=production webpack --colors && cp ./dist/* ../public/assets/
Hash: f5404348a5a4eadca2c5
Version: webpack 2.6.1
Time: 9894ms
Asset Size Chunks Chunk
Names
client-149e7f81934ccd4797d6.bundle.js.map 183 kB 1 [emitted] client
0-b065752a37e19efffbe1.bundle.js 318 bytes 0 [emitted]
webpack-chunk-manifest.json 79 bytes [emitted]
vendor-411f8db22ac4a264ff0d.bundle.js 265 kB 2 [emitted] [big] vendor
client-e9da9d78d42878a4c3a5a7ab1330ea79.css 2.7 kB 1 [emitted] client
0-b065752a37e19efffbe1.bundle.js.map 2.11 kB 0 [emitted]
client-149e7f81934ccd4797d6.bundle.js 24 kB 1 [emitted] client
client-e9da9d78d42878a4c3a5a7ab1330ea79.css.map 120 bytes 1 [emitted] client
client-149e7f81934ccd4797d6.bundle.js.gz 8.35 kB [emitted]
vendor-411f8db22ac4a264ff0d.bundle.js.gz 77.9 kB [emitted]
index.html 493 bytes [emitted]
webpack-asset-manifest.json 468 bytes [emitted]
new webpack.HashedModuleIdsPlugin(),
new ManifestPlugin({ 

fileName: 'webpack-asset-manifest.json' 

}), 



new ChunkManifestPlugin({ 

filename: 'webpack-chunk-manifest.json', 

manifestVariable: 'webpackManifest' 

}), 

// webpack-chunk-manifest.json
{"0":"0-b065752a37e19efffbe1.bundle.js"} 

// webpack-asset-manifest.json

{ 

"0-b065752a37e19efffbe1.bundle.js": "0-b065752a37e19efffbe1.bundle.js", 

"0-b065752a37e19efffbe1.bundle.js.map": "0-b065752a37e19efffbe1.bundle.js.map", 

"client.css": "client-e9da9d78d42878a4c3a5a7ab1330ea79.css", 

"client.css.map": "client-e9da9d78d42878a4c3a5a7ab1330ea79.css.map", 

"client.js": "client-149e7f81934ccd4797d6.bundle.js", 

"client.js.map": "client-149e7f81934ccd4797d6.bundle.js.map", 

"vendor.js": "vendor-411f8db22ac4a264ff0d.bundle.js" 

} 

4 bundles
vendor.js client.js 0.js client.css
html from server
/* … */
<script type=“text/javascript”>
window.apiEndPoint = "http://stage.example.com"
</script>
<link href="//xxx/client.css" rel="stylesheet" />
<script src="//xxx/vendor.js”></script>
<script src="//xxx/client.js"></script>
/* … */
} xxx=?
<div id="root"></div>
<%= api_endpoint_from_environment %>
<%= client_application_stylesheet_tag 'client.css' %>

<%= client_application_javascript_tag 'vendor.js' %> 

<%= client_application_javascript_tag 'client.js' %> 

server template
module ClientApplicationHelper
# client_application_javascript_tag 'client.js'

def client_application_javascript_tag(bundle) 

src = 

if client_application[:use_manifest]
# "client.js": "client-149e7f81934ccd4797d6.bundle.js", 

manifest = client_application[:asset_manifest][bundle]


# static asset

"/assets/#{bundle}" 

else
# dev mode

"http://localhost:9001/assets/#{bundle}" 

end 



javascript_include_tag(src)

end 



def client_application_stylesheet_tag(bundle)
# …
# almost the same but no need to render in dev mode

end 

end 



serve from
• webpack dev server (for dev mode)
• same server, static assets
• static assets through CDN
• CDN direct
• whatever
awesome
almost awesome
<%= client_application_stylesheet_tag 'client.css' %>
<%= client_application_javascript_tag 'vendor.js' %> 

<%= client_application_javascript_tag 'client.js' %> 

in a context of a request
current_user
req.current_user, request.user[. is_authenticated], …
module ClientApplicationHelper


def client_application_javascript_tag(bundle) 

src = 

if client_application[:use_manifest]
# "client.js": "client-149e7f81934ccd4797d6.bundle.js", 

manifest = assets_manifest_for(current_user)[bundle]

# …

end 



javascript_include_tag(src)

end 

end 



storing manifests per user
S3, database, redis, memcache, etc
+ default manifest for the rest of the users
assets_manifest_for(current_user)[bundle]
• A/B testing
• features testing in production env
• UI experiments
• gradually rolling out new features
assets_manifest_for(current_user)[bundle]
bundles v1.12
default
bundles v1.13
debugging an issue
bundles v2.0
testing new release
user with a bug in v1.12
marketing user
all users
separate server and client
deployments
client lifecycle
• build: get new bundles + manifest
• deploy: upload bundles to remote
storage (S3) + warm up CDN
• release: update user’s or default
manifest
awesome
almost awesome
http://www.enjoyart.com/single_posters/animals_art_photo/NoahsArkTakinoAnimalsArtPrintPoster.htm
zoo
bundles v2.0bundles v2.1bundles v2.2bundles v2.3bundles v2.4
server
compatibility
API
compatibility
develop deploy test release
new frontend version
new backend version
local staging production
release = update default manifest
for all the users
server first
server is always backward compatible
easier to maintain compatibility on server with API versioning
zoo = not an engineering issue
but administrative one
awesome
really awesome
https://github.com/astrails/rails_react_webpack
thanks to mike@astrails.com aka @mihap
http://astrails.com/blog
slides will be available
thanks!
Boris Nadion
http://astrails.com
boris@astrails.com
@borisnadion

More Related Content

What's hot (20)

PDF
Laravel 8 export data as excel file with example
Katy Slemon
 
PDF
Instant and offline apps with Service Worker
Chang W. Doh
 
PDF
An introduction to Vue.js
Javier Lafora Rey
 
PDF
A gently introduction to AngularJS
Gregor Woiwode
 
PDF
20130528 solution linux_frousseau_nopain_webdev
Frank Rousseau
 
PDF
webcomponents (Jfokus 2015)
Hendrik Ebbers
 
PDF
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
Rob Tweed
 
PDF
Using ReactJS in AngularJS
Boris Dinkevich
 
PDF
Introducing Rendr: Run your Backbone.js apps on the client and server
Spike Brehm
 
PDF
The Complementarity of React and Web Components
Andrew Rota
 
PDF
Building a Startup Stack with AngularJS
FITC
 
PDF
Javascript MVVM with Vue.JS
Eueung Mulyana
 
PDF
Vaadin Components
Joonas Lehtinen
 
PDF
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
IT Event
 
ODP
AngularJs Crash Course
Keith Bloomfield
 
PDF
Building Universal Web Apps with React ForwardJS 2017
Elyse Kolker Gordon
 
PPTX
Meteor Day Talk
Brandon Bechtel
 
PDF
The Point of Vue - Intro to Vue.js
Holly Schinsky
 
PDF
Hastening React SSR - Web Performance San Diego
Maxime Najim
 
PPTX
Node JS Express : Steps to Create Restful Web App
Edureka!
 
Laravel 8 export data as excel file with example
Katy Slemon
 
Instant and offline apps with Service Worker
Chang W. Doh
 
An introduction to Vue.js
Javier Lafora Rey
 
A gently introduction to AngularJS
Gregor Woiwode
 
20130528 solution linux_frousseau_nopain_webdev
Frank Rousseau
 
webcomponents (Jfokus 2015)
Hendrik Ebbers
 
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
Rob Tweed
 
Using ReactJS in AngularJS
Boris Dinkevich
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Spike Brehm
 
The Complementarity of React and Web Components
Andrew Rota
 
Building a Startup Stack with AngularJS
FITC
 
Javascript MVVM with Vue.JS
Eueung Mulyana
 
Vaadin Components
Joonas Lehtinen
 
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
IT Event
 
AngularJs Crash Course
Keith Bloomfield
 
Building Universal Web Apps with React ForwardJS 2017
Elyse Kolker Gordon
 
Meteor Day Talk
Brandon Bechtel
 
The Point of Vue - Intro to Vue.js
Holly Schinsky
 
Hastening React SSR - Web Performance San Diego
Maxime Najim
 
Node JS Express : Steps to Create Restful Web App
Edureka!
 

Similar to Building and deploying React applications (20)

PDF
Front-end build tools - Webpack
Razvan Rosu
 
PDF
How to replace rails asset pipeline with webpack?
Tomasz Bak
 
PDF
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
Alain Hippolyte
 
PDF
Creating a full stack web app with python, npm, webpack and react
Angela Kristine Juvet Branaes
 
PDF
(2018) Webpack Encore - Asset Management for the rest of us
Stefan Adolf
 
PDF
React on rails v6.1 at LA Ruby, November 2016
Justin Gordon
 
PDF
Installing Webpack with React JS from Scratch.pdf
Sufalam Technologies
 
PPTX
An Intro into webpack
Squash Apps Pvt Ltd
 
PDF
React on rails v4
Justin Gordon
 
PDF
Webpack presentation
RAHUL SHARMA
 
PDF
Server side rendering with React and Symfony
Ignacio Martín
 
PPTX
How create react app help in creating a new react applications
Concetto Labs
 
PDF
Bundle your modules with Webpack
Jake Peyser
 
PDF
Webpack Encore - Asset Management for the rest of us
Stefan Adolf
 
PDF
Rails 6 frontend frameworks
Eric Guo
 
PDF
Webpack Encore Symfony Live 2017 San Francisco
Ryan Weaver
 
PPTX
WEBPACK
home
 
PPTX
Lecture: Webpack 4
Sergei Iastrebov
 
PDF
Front End Development for Back End Developers - Denver Startup Week 2017
Matt Raible
 
PDF
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Ryan Weaver
 
Front-end build tools - Webpack
Razvan Rosu
 
How to replace rails asset pipeline with webpack?
Tomasz Bak
 
Symfony Live 2018 - Développez votre frontend avec ReactJS et Symfony Webpack...
Alain Hippolyte
 
Creating a full stack web app with python, npm, webpack and react
Angela Kristine Juvet Branaes
 
(2018) Webpack Encore - Asset Management for the rest of us
Stefan Adolf
 
React on rails v6.1 at LA Ruby, November 2016
Justin Gordon
 
Installing Webpack with React JS from Scratch.pdf
Sufalam Technologies
 
An Intro into webpack
Squash Apps Pvt Ltd
 
React on rails v4
Justin Gordon
 
Webpack presentation
RAHUL SHARMA
 
Server side rendering with React and Symfony
Ignacio Martín
 
How create react app help in creating a new react applications
Concetto Labs
 
Bundle your modules with Webpack
Jake Peyser
 
Webpack Encore - Asset Management for the rest of us
Stefan Adolf
 
Rails 6 frontend frameworks
Eric Guo
 
Webpack Encore Symfony Live 2017 San Francisco
Ryan Weaver
 
WEBPACK
home
 
Lecture: Webpack 4
Sergei Iastrebov
 
Front End Development for Back End Developers - Denver Startup Week 2017
Matt Raible
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Ryan Weaver
 
Ad

More from Astrails (12)

PDF
Accounting For Hackers
Astrails
 
PDF
Machine Learning: Make Your Ruby Code Smarter
Astrails
 
PDF
Migrating from Flux to Redux. Why and how.
Astrails
 
PDF
Engineering esthetics
Astrails
 
PDF
Lean Software Development
Astrails
 
PDF
RubyMotion: Put your Dreams in Motion with Ruby
Astrails
 
PDF
WTF is NoSQL
Astrails
 
PDF
Cassandra intro
Astrails
 
PDF
Ruby is an Acceptable Lisp
Astrails
 
PDF
Ruby is Awesome
Astrails
 
PDF
Rails missing features
Astrails
 
PDF
Performance - When, What and How
Astrails
 
Accounting For Hackers
Astrails
 
Machine Learning: Make Your Ruby Code Smarter
Astrails
 
Migrating from Flux to Redux. Why and how.
Astrails
 
Engineering esthetics
Astrails
 
Lean Software Development
Astrails
 
RubyMotion: Put your Dreams in Motion with Ruby
Astrails
 
WTF is NoSQL
Astrails
 
Cassandra intro
Astrails
 
Ruby is an Acceptable Lisp
Astrails
 
Ruby is Awesome
Astrails
 
Rails missing features
Astrails
 
Performance - When, What and How
Astrails
 
Ad

Recently uploaded (20)

PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 

Building and deploying React applications