SlideShare a Scribd company logo
1 of 36
Download to read offline
从 Assets Pipeline 到 Webpack,
Rails 6 的前端⽅方案们
From assets pipeline to web pack, 

the Rails 6 frontend frameworks
过纯中 @Eric-Guo
演讲路路线图 - Talk Roadmap
The Rails 6 new FrontEnd choice Asset Pipeline
WebpackCore FE problem
View
Reuse the view
Server Side Rendering
React Component
Jquery plugin
Solve mix problem
Turbolink
State
Sync State
form_encode
API
Redux
DOM
stimulus.js
Bootstrap
My Framework
React
stimulus.js
Bootstrap
CoreUI
Real code review
SignIn form
(turbolink)
Chart drill down
(echart with stimulus.js)
Tableau style
(react-pivottable)
Mix them all
Rails as API onlyJWT
-https://guides.rubyonrails.org/asset_pipeline.html
The asset pipeline provides a framework
to concatenate and minify or compress
JavaScript and CSS assets.
-https://guides.rubyonrails.org/asset_pipeline.html
The asset pipeline provides a framework
to concatenate and minify or compress
JavaScript and CSS assets.
concatenate
Processors (Autoprefix)
Transformers (CoffeeScript)
compress
Compressors (Uglify)
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md
Assets pipeline usage
//= require activestorage
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Assets pipeline usage optimization
https://github.com/thape-cn/website/commit/dff05e24c59e5d62f7de8b33e9cebd02a2861247#diff-a9c3bd311eab80c9ebe6a69830f9ad02L20
//= require activestorage
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require admin/infos
//= require blackapp
Assets Pipeline Problem
• JS wrap gem

• Webpack solution

• Yarn usage without webpack

• https://github.com/Eric-Guo/product_hunt

• Slowness

• Do not use require require_tree and require_self in your SASS/
SCSS files.

• ES 6 Support

• Sprocket 4 and ruby-babel-transpiler
https://ruby-china.org/topics/38832#为什什么要使⽤用%20webpacker
solution
https://webpack.js.org/concepts/
Webpack is a static module bundler for
modern JavaScript applications.
Webpack
Webpack concept
•Dependency graph

•Entry

•Output

•Loaders

•To load other file type, except .js

•style-loader: Add CSS to the DOM by injecting a <style> tag

•css-loader: interprets @import and url() and resolves them

•sass-loader: compiles Sass to CSS, using Node Sass

•vue-loader: .vue to .js, .css, .css.map

•Plugins

•serve the purpose of doing anything else that a loader cannot do! (yes, it’s on the
official document!)
Webpacker
WEBPACKER QUICK LOOK
• Start in Rails 5.1+

• Current V4 same version of Webpack 4

• Guide to switch from Sprockets to Webpacker

• The missing guides

• https://github.com/rails/webpacker/tree/master/docs
const importAll = (r) => r.keys().map(r)
importAll(require.context('images', false, /.(png|jpe?g|svg)$/i));
import "regenerator-runtime/runtime";
import "@stimulus/polyfills";
import JQuery from 'jquery';
window.$ = window.JQuery = JQuery;
import "bootstrap"
import "@coreui/coreui"
Legacy application.js support IE11
The @ scope indicates package ownership
import "stylesheets/application"
Legacy application.scss file
~ to tell webpack that this is not a relative import:
import "stylesheets/application"
@import "variables";
@import "~@coreui/coreui/scss/coreui";
@import "custom";
$fa-font-path: "~@fortawesome/fontawesome-free/webfonts";
@import "~@fortawesome/fontawesome-free/scss/fontawesome";
@import "~@fortawesome/fontawesome-free/scss/regular";
@import "~@fortawesome/fontawesome-free/scss/solid";
# Extract and emit a css
# config/webpacker.ymls
extract_css: true
Assets Pipeline
Webpack
Javascript source file app/assets/javascripts
Sass source file app/assets/stylesheets
Output folder public/assets/
Javascript source file app/javascript/
Sass source file app/assets/stylesheets (same)
Output folder public/packs/
Assets Pipeline
Webpack
Sprockets concatenates
Webpack adds unique dependencies
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
Webpacker official frontend framework
• React

• Angular with TypeScript

• Vue

• Elm

• Stimulus

• Svelte

• CoffeeScript

• Bootstrap

• Erb
https://github.com/rails/webpacker#integrations
My frontend framework
• React

• Redux

• Taro

• Stimulus

• Easy integrating Turbolinks and echarts

• Middle code solution

• Bootstrap

• CoreUI / Cybros as backend

• Low code solution
cybros / Bootstrap login with JWT AUD
https://github.com/jasl/cybros_core/pull/16/commits/fdbf67161c32b54864a0f7f581b4285aa16b0c5c
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
ready(function() {
const sign_form = document.getElementById("user-sign-in")
if (sign_form != null) {
sign_form.addEventListener('ajax:beforeSend', function(event, settings) {
const xhr = event.detail[0];
xhr.setRequestHeader('JWT_AUD', 'cybros_core');
});
}
});
cybros_core / Bootstrap State
• Cybros not integrated jQuery

• Low code means low level code instead of small amount of code 😂

• Need to fully understanding @rails/ujs

• Need reading ujs source code

• Many js component available

• Bootstrap: Modals, Toast, Dropdown, Navbar, Carousel, Popover

• CoreUI: Aside menu

• Most solid/popular CSS framework
Stimulus with echarts
Stimulus with Turbolinks is SPA
<div class="row">
<div class="col-lg-12">
<div id="project-milestore-chart"
data-controller="project-milestores"
data-action="resize@window->project-milestores#layout"
data-project-milestores-x_axis="<%= @deptnames_in_order.to_json -%>"
data-project-milestores-milestore_rate="<%= @milestore_rate.to_json -%>"
style="width: 100%;height: 350px;">
</div>
</div>
</div>
1 import { Controller } from "stimulus"
2
3 let projectMilestoreChart;
4
5 export default class extends Controller {
6 connect() {
7 projectMilestoreChart = echarts.init(document.getElementById('project-milestore-chart'));
8
9 const xAxisData = JSON.parse(this.data.get("x_axis"));
10 const milestoreUpdateRate = JSON.parse(this.data.get("milestore_update_rate"));
11
12 const option = {...
13 };
14
15 {…}
16
17 projectMilestoreChart.on('click', drill_down_contract_detail);
18
19 projectMilestoreChart.setOption(option, false);
20 setTimeout(() => { projectMilestoreChart.resize(); }, 200);
21 }
22
23 layout() {
24 projectMilestoreChart.resize();
25 }
26
27 disconnect() {
28 projectMilestoreChart.dispose();
29 }
30 }
function drill_down_contract_detail(params)
$(“#project-milestore-modal")
.html(‘<%= j render partial: "modal", locals: { rows: @rows } -%>');
$("#project-milestore-modal").modal();
{
if (params.componentType === 'series') {
if (params.seriesType === 'line') {
const department_name = xAxisData[params.dataIndex];
const month_name = $('#month_name').val();
const sent_data = { department_name, month_name };
const drill_down_url = '/report/project_milestore/detail_drill_down';
$.ajax(drill_down_url, {
data: sent_data,
dataType: 'script'
});
}
}
}
Enable the drill down echart
function drill_down_contract_detail(params)
Stimulus.js / eChart State
• Writen by Sam Stephenson (who write prototypejs 15 years
ago)

• No UI render support

• SSR (Server Side Rendering using Rails render method)

• Easy to integrated 3rd party js package.

• 99.9% reliable with Turbolink.

• Minority population
Where are our STATE now?
The Rails 6 Asset Pipeline
Webpack
View
partial render
React
jQuery plugin
Turbolink
State
form
Restful API
Redux
DOM
stimulus.js
Bootstrap
React
stimulus.js
Bootstrap
CoreUI
(turbolink)
(echart with stimulus.js)
(react-pivottable)
JWT
Rails MVC
• State at DB

• Stateless in Browser

• No ajax
React with Redux
Store
MiddlewareUI
Action
Action
New
state
Redux-Thunk
Redux-Saga
Store
MiddlewareUI
Action
Action
New
state
State in
Browser
State in DB
Mix the React and Redux with Rails
will cause two state problem
React in Rails options
• Do not using Redux

• react-rails gem

• See bluedoc.io as example ❤ 李李华顺 

• Using Rails as API only.
React-Redux with Rails API
• Book code

• React 进阶之路路 Blog 实现

• https://github.com/Eric-Guo/the-react-way-in-blog

• Frontend

• Todo App example 

• https://github.com/Eric-Guo/react-redux-loginform/commits/pangu_backend

• Backend

• devise-jwt

• https://github.com/Eric-Guo/rails-pangu/tree/react-redux-loginform-backend
My Rails 6 Frontend Framework
Options Pro Cons State Storage
jQuery Quick and Short No state concept DOM
Stimulus.js Simple and modest Less popular data-*
React High salary Hard to learn Redux
Taro
Wechat MP+H5+React
Native
Unknown Redux
jQuery
Stimulus.js
React
Taro
jQuery
Stimulus.js
React
Taro
Mix them all
Reference
• RailsConf 2019 - Webpacker vs Asset Pipeline by Danielle Gordon

• webpack (1)——核⼼心概念的理理解

• Rails 6 template 

• https://github.com/jasl/cybros_core

• Rails 6 API temple

• https://github.com/paiyou-network/rails-pangu

• 《React 进阶之路路》

More Related Content

What's hot

Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Chris Alfano
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09Michelangelo van Dam
 
Arquitetura de Front-end em Aplicações de Larga Escala
Arquitetura de Front-end em Aplicações de Larga EscalaArquitetura de Front-end em Aplicações de Larga Escala
Arquitetura de Front-end em Aplicações de Larga EscalaEduardo Shiota Yasuda
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceParashuram N
 
PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014cagataycivici
 
Headless Drupal en pratique
Headless Drupal en pratiqueHeadless Drupal en pratique
Headless Drupal en pratiqueSimon Morvan
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegapyangdj
 
Practical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingPractical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingNatasha Murashev
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverSpike Brehm
 
Oracle APEX Performance
Oracle APEX PerformanceOracle APEX Performance
Oracle APEX PerformanceScott Wesley
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVCAcquisio
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications Juliana Lucena
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0Eyal Vardi
 

What's hot (19)

Node.js server-side rendering
Node.js server-side renderingNode.js server-side rendering
Node.js server-side rendering
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
 
Modular and Event-Driven JavaScript
Modular and Event-Driven JavaScriptModular and Event-Driven JavaScript
Modular and Event-Driven JavaScript
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
Arquitetura de Front-end em Aplicações de Larga Escala
Arquitetura de Front-end em Aplicações de Larga EscalaArquitetura de Front-end em Aplicações de Larga Escala
Arquitetura de Front-end em Aplicações de Larga Escala
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and Performance
 
PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014
 
Headless Drupal en pratique
Headless Drupal en pratiqueHeadless Drupal en pratique
Headless Drupal en pratique
 
Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegap
 
Practical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingPractical Protocol-Oriented-Programming
Practical Protocol-Oriented-Programming
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and server
 
Oracle APEX Performance
Oracle APEX PerformanceOracle APEX Performance
Oracle APEX Performance
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVC
 
Pyramid REST
Pyramid RESTPyramid REST
Pyramid REST
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
 

Similar to Rails 6 frontend frameworks

How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?Tomasz Bak
 
Curing Webpack Cancer
Curing Webpack CancerCuring Webpack Cancer
Curing Webpack CancerNeel Shah
 
Quick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase ServerQuick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase ServerNic Raboy
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fastHow Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fastAtlassian
 
Everything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebEverything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebJames Rakich
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Eliran Eliassy
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
 
Reusing your frontend JS on the server with V8/Rhino
Reusing your frontend JS on the server with V8/RhinoReusing your frontend JS on the server with V8/Rhino
Reusing your frontend JS on the server with V8/RhinoKenneth Kalmer
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)Igor Bronovskyy
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Elyse Kolker Gordon
 
以Vue開發電子商務網站
架構與眉角
以Vue開發電子商務網站
架構與眉角以Vue開發電子商務網站
架構與眉角
以Vue開發電子商務網站
架構與眉角Mei-yu Chen
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoasZeid Hassan
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Codemotion
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Luciano Mammino
 

Similar to Rails 6 frontend frameworks (20)

How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?
 
Curing Webpack Cancer
Curing Webpack CancerCuring Webpack Cancer
Curing Webpack Cancer
 
Quick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase ServerQuick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase Server
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fastHow Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
 
Nodejs.meetup
Nodejs.meetupNodejs.meetup
Nodejs.meetup
 
Everything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebEverything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the Web
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
Reusing your frontend JS on the server with V8/Rhino
Reusing your frontend JS on the server with V8/RhinoReusing your frontend JS on the server with V8/Rhino
Reusing your frontend JS on the server with V8/Rhino
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017
 
以Vue開發電子商務網站
架構與眉角
以Vue開發電子商務網站
架構與眉角以Vue開發電子商務網站
架構與眉角
以Vue開發電子商務網站
架構與眉角
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoas
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
 

Recently uploaded

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Rails 6 frontend frameworks

  • 1. 从 Assets Pipeline 到 Webpack, Rails 6 的前端⽅方案们 From assets pipeline to web pack, the Rails 6 frontend frameworks 过纯中 @Eric-Guo
  • 2. 演讲路路线图 - Talk Roadmap The Rails 6 new FrontEnd choice Asset Pipeline WebpackCore FE problem View Reuse the view Server Side Rendering React Component Jquery plugin Solve mix problem Turbolink State Sync State form_encode API Redux DOM stimulus.js Bootstrap My Framework React stimulus.js Bootstrap CoreUI Real code review SignIn form (turbolink) Chart drill down (echart with stimulus.js) Tableau style (react-pivottable) Mix them all Rails as API onlyJWT
  • 3. -https://guides.rubyonrails.org/asset_pipeline.html The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets.
  • 4. -https://guides.rubyonrails.org/asset_pipeline.html The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets.
  • 5. concatenate Processors (Autoprefix) Transformers (CoffeeScript) compress Compressors (Uglify) https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md
  • 6. Assets pipeline usage //= require activestorage //= require jquery //= require bootstrap-sprockets //= require jquery_ujs //= require turbolinks //= require_tree .
  • 7. Assets pipeline usage optimization https://github.com/thape-cn/website/commit/dff05e24c59e5d62f7de8b33e9cebd02a2861247#diff-a9c3bd311eab80c9ebe6a69830f9ad02L20 //= require activestorage //= require jquery //= require bootstrap-sprockets //= require jquery_ujs //= require turbolinks //= require admin/infos //= require blackapp
  • 8. Assets Pipeline Problem • JS wrap gem • Webpack solution • Yarn usage without webpack • https://github.com/Eric-Guo/product_hunt • Slowness • Do not use require require_tree and require_self in your SASS/ SCSS files. • ES 6 Support • Sprocket 4 and ruby-babel-transpiler https://ruby-china.org/topics/38832#为什什么要使⽤用%20webpacker
  • 10. https://webpack.js.org/concepts/ Webpack is a static module bundler for modern JavaScript applications.
  • 12. Webpack concept •Dependency graph •Entry •Output •Loaders •To load other file type, except .js •style-loader: Add CSS to the DOM by injecting a <style> tag •css-loader: interprets @import and url() and resolves them •sass-loader: compiles Sass to CSS, using Node Sass •vue-loader: .vue to .js, .css, .css.map •Plugins •serve the purpose of doing anything else that a loader cannot do! (yes, it’s on the official document!)
  • 14. WEBPACKER QUICK LOOK • Start in Rails 5.1+ • Current V4 same version of Webpack 4 • Guide to switch from Sprockets to Webpacker • The missing guides • https://github.com/rails/webpacker/tree/master/docs
  • 15. const importAll = (r) => r.keys().map(r) importAll(require.context('images', false, /.(png|jpe?g|svg)$/i)); import "regenerator-runtime/runtime"; import "@stimulus/polyfills"; import JQuery from 'jquery'; window.$ = window.JQuery = JQuery; import "bootstrap" import "@coreui/coreui" Legacy application.js support IE11 The @ scope indicates package ownership import "stylesheets/application"
  • 16. Legacy application.scss file ~ to tell webpack that this is not a relative import: import "stylesheets/application" @import "variables"; @import "~@coreui/coreui/scss/coreui"; @import "custom"; $fa-font-path: "~@fortawesome/fontawesome-free/webfonts"; @import "~@fortawesome/fontawesome-free/scss/fontawesome"; @import "~@fortawesome/fontawesome-free/scss/regular"; @import "~@fortawesome/fontawesome-free/scss/solid"; # Extract and emit a css # config/webpacker.ymls extract_css: true
  • 17. Assets Pipeline Webpack Javascript source file app/assets/javascripts Sass source file app/assets/stylesheets Output folder public/assets/ Javascript source file app/javascript/ Sass source file app/assets/stylesheets (same) Output folder public/packs/
  • 18. Assets Pipeline Webpack Sprockets concatenates Webpack adds unique dependencies <%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
  • 19. Webpacker official frontend framework • React • Angular with TypeScript • Vue • Elm • Stimulus • Svelte • CoffeeScript • Bootstrap • Erb https://github.com/rails/webpacker#integrations
  • 20. My frontend framework • React • Redux • Taro • Stimulus • Easy integrating Turbolinks and echarts • Middle code solution • Bootstrap • CoreUI / Cybros as backend • Low code solution
  • 21. cybros / Bootstrap login with JWT AUD https://github.com/jasl/cybros_core/pull/16/commits/fdbf67161c32b54864a0f7f581b4285aa16b0c5c function ready(fn) { if (document.readyState != 'loading'){ fn(); } else { document.addEventListener('DOMContentLoaded', fn); } } ready(function() { const sign_form = document.getElementById("user-sign-in") if (sign_form != null) { sign_form.addEventListener('ajax:beforeSend', function(event, settings) { const xhr = event.detail[0]; xhr.setRequestHeader('JWT_AUD', 'cybros_core'); }); } });
  • 22. cybros_core / Bootstrap State • Cybros not integrated jQuery • Low code means low level code instead of small amount of code 😂 • Need to fully understanding @rails/ujs • Need reading ujs source code • Many js component available • Bootstrap: Modals, Toast, Dropdown, Navbar, Carousel, Popover • CoreUI: Aside menu • Most solid/popular CSS framework
  • 24. Stimulus with Turbolinks is SPA <div class="row"> <div class="col-lg-12"> <div id="project-milestore-chart" data-controller="project-milestores" data-action="resize@window->project-milestores#layout" data-project-milestores-x_axis="<%= @deptnames_in_order.to_json -%>" data-project-milestores-milestore_rate="<%= @milestore_rate.to_json -%>" style="width: 100%;height: 350px;"> </div> </div> </div>
  • 25. 1 import { Controller } from "stimulus" 2 3 let projectMilestoreChart; 4 5 export default class extends Controller { 6 connect() { 7 projectMilestoreChart = echarts.init(document.getElementById('project-milestore-chart')); 8 9 const xAxisData = JSON.parse(this.data.get("x_axis")); 10 const milestoreUpdateRate = JSON.parse(this.data.get("milestore_update_rate")); 11 12 const option = {... 13 }; 14 15 {…} 16 17 projectMilestoreChart.on('click', drill_down_contract_detail); 18 19 projectMilestoreChart.setOption(option, false); 20 setTimeout(() => { projectMilestoreChart.resize(); }, 200); 21 } 22 23 layout() { 24 projectMilestoreChart.resize(); 25 } 26 27 disconnect() { 28 projectMilestoreChart.dispose(); 29 } 30 } function drill_down_contract_detail(params)
  • 26. $(“#project-milestore-modal") .html(‘<%= j render partial: "modal", locals: { rows: @rows } -%>'); $("#project-milestore-modal").modal(); { if (params.componentType === 'series') { if (params.seriesType === 'line') { const department_name = xAxisData[params.dataIndex]; const month_name = $('#month_name').val(); const sent_data = { department_name, month_name }; const drill_down_url = '/report/project_milestore/detail_drill_down'; $.ajax(drill_down_url, { data: sent_data, dataType: 'script' }); } } } Enable the drill down echart function drill_down_contract_detail(params)
  • 27. Stimulus.js / eChart State • Writen by Sam Stephenson (who write prototypejs 15 years ago) • No UI render support • SSR (Server Side Rendering using Rails render method) • Easy to integrated 3rd party js package. • 99.9% reliable with Turbolink. • Minority population
  • 28. Where are our STATE now? The Rails 6 Asset Pipeline Webpack View partial render React jQuery plugin Turbolink State form Restful API Redux DOM stimulus.js Bootstrap React stimulus.js Bootstrap CoreUI (turbolink) (echart with stimulus.js) (react-pivottable) JWT
  • 29. Rails MVC • State at DB • Stateless in Browser • No ajax
  • 31. Store MiddlewareUI Action Action New state State in Browser State in DB Mix the React and Redux with Rails will cause two state problem
  • 32. React in Rails options • Do not using Redux • react-rails gem • See bluedoc.io as example ❤ 李李华顺 • Using Rails as API only.
  • 33. React-Redux with Rails API • Book code • React 进阶之路路 Blog 实现 • https://github.com/Eric-Guo/the-react-way-in-blog • Frontend • Todo App example • https://github.com/Eric-Guo/react-redux-loginform/commits/pangu_backend • Backend • devise-jwt • https://github.com/Eric-Guo/rails-pangu/tree/react-redux-loginform-backend
  • 34. My Rails 6 Frontend Framework Options Pro Cons State Storage jQuery Quick and Short No state concept DOM Stimulus.js Simple and modest Less popular data-* React High salary Hard to learn Redux Taro Wechat MP+H5+React Native Unknown Redux jQuery Stimulus.js React Taro
  • 36. Reference • RailsConf 2019 - Webpacker vs Asset Pipeline by Danielle Gordon • webpack (1)——核⼼心概念的理理解 • Rails 6 template • https://github.com/jasl/cybros_core • Rails 6 API temple • https://github.com/paiyou-network/rails-pangu • 《React 进阶之路路》