SlideShare a Scribd company logo
ES6 in Production
JSConf Uruguay 2015
- Made in Buenos Aires, Argentina
- Front-end Developer
- Working at Mango
@pazguille (twitter / github)
Guille Paz
#ES6inProd
Your feedback is welcome!
ES6
Hi!
https://getmango.com
Why?
Why?
Future
Why?
Why?
Code
Why?
● Write expressive code
Why?
● Write expressive code
● Easier to understand
Why?
● Write expressive code
● Easier to understand
● Standardizes commons practices
Why?
ES6 Modules
define('Slideout',
// Deps
['inherit', 'Emitter'],
// Slideout
function(inherit, Emitter) {
function Slideout(options) { … }
// Export
return Slideout;
});
Why?
AMD
// Deps
var inherit = require('inherit');
var Emitter = require('emitter');
// Slideout
function Slideout(options) { … }
// Export
module.exports = Slideout;
Why?
CommonJS
Why?
ES6 Modules
// Deps
import inherit from 'inherit';
import Emitter from 'emitter';
// Slideout
function Slideout(options) { … }
// Export
export default Slideout;
Why?
Classes
ES6 in Production [JSConfUY2015]
// Slideout
function Slideout(options) { … }
// Inherit from Emitter
inherit(Slideout, Emitter);
// Extend prototype
Slideout.prototype.open = function() { … };
Why?
Classes
// Slideout
class Slideout extends Emitter {
constructor(options={}) { … }
open() { … }
}
Why?
Classes
// Deps
var inherit = require('inherit');
var Emitter = require('emitter');
// Slideout
function Slideout(options) { … }
// Inherit from Emitter
inherit(Slideout, Emitter);
// Extend prototype
Slideout.prototype.open = function() { … };
// Export
module.exports = Slideout;
Why?
// Deps
var inherit = require('inherit');
var Emitter = require('emitter');
// Slideout
function Slideout(options) { … }
// Inherit from Emitter
inherit(Slideout, Emitter);
// Extend prototype
Slideout.prototype.open = function() { … };
// Export
module.exports = Slideout;
Why?
// Deps
import Emitter from 'emitter';
// Slideout
class Slideout extends Emitter {
constructor(options={}) { … }
open() { … }
}
// Export
export default Slideout;
Why?
Classes
arrow = > functions
Module Syntax
let/const
Rest Parameters
Templates Strings Default Parameters
getmango.com/blog
https://getmango.com/blog/writing-es6-modules-with-6to5/
How?
Transpilers
How?
How?
ES6 ES5
How?
How?
Build Process
How?
How?
browserify({'entries': opts.entries, 'debug': true})
.plugin('factor-bundle', {'outputs': opts.bundles})
.on('error', function(err) { … })
.bundle()
.pipe(fs.createWriteStream(opts.output));
How?
How?
Babelify
browserify({'entries': opts.entries, 'debug': true})
.plugin('factor-bundle', {'outputs': opts.bundles})
.transform('babelify')
.on('error', function(err) { … })
.bundle()
.pipe(fs.createWriteStream(opts.output));
How?
Browser
How?
How?
http://kangax.github.io/compat-table/es5/
ES5
Polyfills
How?
How?
http://kangax.github.io/compat-table/es6/
ES6
core-js
How?
https://github.com/zloirock/core-js
How?
es5.js
(IE < 9)
Custom build
https://github.com/zloirock/core-js
How?
es5.js
(IE < 9)
es6.js
(all)
Custom build
https://github.com/zloirock/core-js
index.html
How?
…
<!--[if lt IE 9]>
<script src="/js/es5.js"></script>
<![endif]-->
<script src="/js/es6.js"></script>
<script src="/js/build.js"></script>
</body>
ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]
Issues
Issues
Context
~110 modules
Issues
Issues
ES5 / ES6
Issues
Dependencies
Issues
Issues
├─ src
├─ boot.js
└─ bus.js
├─ package.json
├─ test
└─ node_modules
├─ slideout
└─ emitter
Dashboard
ES6
ES6
Issues
bus.js
// Deps
import Emitter from 'emitter';
// bus
const bus = new Emitter();
// Export
export default bus;
Issues
…
exports['default'] = bus;
module.exports = exports['default'];
},{'emitter':2}],2:[function(require,module,exports){
class Emitter {
on(event, listener) {
…
Issues
output.js
ES6 in Production [JSConfUY2015]
Issues
Dashboard
├─ src
├─ boot.js
└─ bus.js
├─ package.json
├─ test
└─ node_modules
├─ slideout
└─ emitter
Babelify
Issues
Dashboard
├─ src
├─ boot.js
└─ bus.js
├─ package.json
├─ test
└─ node_modules
├─ slideout
└─ emitter
Babelify
Issues
Dashboard
├─ src
├─ boot.js
└─ bus.js
├─ package.json
├─ test
└─ node_modules
├─ slideout
└─ emitter
Babelify
global : true
Issues
browserify({'entries': opts.entries, 'debug': true})
.plugin('factor-bundle', {'outputs': opts.bundles})
.transform('babelify')
.on('error', function(err) { … })
.bundle()
.pipe(fs.createWriteStream(opts.output));
Issues
browserify({'entries': opts.entries, 'debug': true})
.plugin('factor-bundle', {'outputs': opts.bundles})
.transform('babelify', {'global': true})
.on('error', function(err) { … })
.bundle()
.pipe(fs.createWriteStream(opts.output));
Issues
…
exports['default'] = bus;
module.exports = exports['default'];
},{'emitter':2}],2:[function(require,module,exports){
var Emitter = (function () {
function Emitter() {
…
Issues
output.js
package.json
Issues
…
"browserify": {
"transform": ["babelify"]
},
…
Issues
Emitter.js - package.json
…
"browserify": {
"transform": ["babelify"]
},
"dependencies": {
"babelify": "6.0.2"
},
…
Issues
Emitter.js - package.json
Issues
Writing ES6
Issues
Publishing ES5
Issues
Issues
Module
├─ src
└─ index.js
├─ package.json
└─ test
Issues
Module
├─ src
└─ index.js
├─ package.json
└─ test
ES6
Issues
Module
ES5
├─ src
└─ index.js
├─ package.json
└─ test
├─ dist
└─ index.js
…
"main": "dist/index.js",
…
Issues
package.json
Issues
Compile Task
(npm, grunt, gulp, broccoli)
…
"main": "dist/index.js",
"script": {
"compile": "babel src --out-dir dist"
},
…
Issues
Compile Task
Issues
npm run compile
…
"main": "dist/index.js",
"script": {
"compile": "babel src --out-dir dist",
"prepublish": "npm run compile"
},
…
Issues
Prepublish Task
mango/emitter
Issues
https://github.com/mango/emitter
Inheritance
Issues
'use strict';
var extend = require('extend');
// Inherits prototype properties
module.exports = function inherit(child, parent) {
extend(child.prototype, parent.prototype);
return parent.prototype;
};
Issues
inherit.js - ES5
Issues
Emitter.js - ES6
class Emitter {
constructor(options={}) { … }
on() { … }
emit() { … }
…
}
export default Emitter;
// Deps
var inherit = require('inherit');
var Emitter = require('emitter');
// Slideout
function Slideout(options) { … }
// Inherit from Emitter
inherit(Slideout, Emitter);
// Extend prototype
Slideout.prototype.open = function() { … };
// Export
module.export = Slideout;
Issues
Slideout.js - ES5
// Deps
var inherit = require('inherit');
var Emitter = require('emitter');
// Slideout
function Slideout(options) { … }
// Inherit from Emitter
inherit(Slideout, Emitter);
// Extend prototype
Slideout.prototype.open = function() { … };
// Export
module.export = Slideout;
Issues
Slideout.js - ES5
console.log(Slideout.prototype);
// { open: function }
Issues
Slideout.js - ES5
console.log(Emitter.prototype);
// { }
Issues
Emitter.js - ES6
Issues
http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts
Issues
class Emitter {
…
on() { … }
…
}
Issues
Emitter.js - ES6
class Emitter {
…
on() { … }
…
}
Issues
Emitter.js - ES5
function Emitter() {}
Object.defineProperties(Emitter.prototype, {
'on': {
'writable': true,
'configurable': true,
'enumerable': false,
'value': function on() {}
}
});
class Emitter {
…
on() { … }
…
}
Issues
Emitter.js - ES5
function Emitter() {}
Object.defineProperties(Emitter.prototype, {
'on': {
'writable': true,
'configurable': true,
'enumerable': false,
'value': function on() {}
}
});
Loose Mode
(babel)
Issues
Issues
es6.classes
browserify({'entries': opts.entries, 'debug': true})
.plugin('factor-bundle', {'outputs': opts.bundles})
.transform('babelify', {'global': true, 'loose': ['es6.classes']})
.on('error', function(err) { … })
.bundle()
.pipe(fs.createWriteStream(opts.output));
Issues
Build Process
class Emitter {
…
on() { … }
…
}
Issues
Emitter.js - ES5
var Emitter = (function () {
function Emitter() { … }
Emitter.prototype.on = function on() {};
…
return Emitter;
})();
console.log(Slideout.prototype);
// { open: function, on: function }
Issues
Slideout.js - ES5
Object.create
Issues
'use strict';
var extend = require('extend');
// Inherits prototype properties.
module.exports = function inherit(child, parent) {
extend(child.prototype, parent.prototype);
return parent.prototype;
};
Issues
inherit.js - ES5
'use strict';
// Inherits prototype properties.
module.exports = function inherit(child, parent) {
child.prototype = Object.create(parent.prototype);
return parent.prototype;
};
Issues
inherit.js - ES5
super() - this
Issues
class Slideout extends Emitter {
constructor(options={}) {
this._padding = options.padding;
…
}
}
Issues
Slideout.js - ES6
Line 12: 'this' is not allowed before super()
Issues
class Slideout extends Emitter {
constructor(options={}) {
this._padding = options.padding;
…
}
}
Issues
Slideout.js - ES6
class Slideout extends Emitter {
constructor(options={}) {
super(options);
this._padding = options.padding;
…
}
}
Issues
Slideout.js - ES6
Issues
https://twitter.com/jashkenas/status/585458831993528320
Issues
http://benmccormick.org/2015/04/07/es6-classes-and-backbone-js/
import & hoisting
Issues
import _ from 'i18n';
import translations from 'translations.json';
_.add(translations);
import login from './login';
…
Issues
Login View - ES6
import _ from 'i18n';
import translations from 'translations.json';
_.add(translations);
import login from './login';
…
Issues
Login View - ES6
Issues
Issues
Login View - ES5
var _import = require('i18n');
var _import2 = _interopRequireWildcard(_import);
var _translations = require('translations.json');
var _translations2 = _interopRequireWildcard(_translations);
var _login = require('./login');
var __login2 = _interopRequireWildcard(__login);
_import2['default'].add(_translations2['default']);
var _import = require('i18n');
var _import2 = _interopRequireWildcard(_import);
var _translations = require('translations.json');
var _translations2 = _interopRequireWildcard(_translations);
var _login = require('./login');
var __login2 = _interopRequireWildcard(__login);
_import2['default'].add(_translations2['default']);
Issues
Login View - ES5
Issues
Babel 4.1.7
Issues
Takeaway
● Transpile to ES5 (Babel)
Takeaway
● Transpile to ES5 (Babel)
● Use ES5/ES6 polyfills (core-js)
Takeaway
● Transpile to ES5 (Babel)
● Use ES5/ES6 polyfills (core-js)
● Babelify: opts.global or package.json
Takeaway
Takeaway
● Transpile to ES5 (Babel)
● Use ES5/ES6 polyfills (core-js)
● Babelify: opts.global or package.json
● Write ES6, publish ES5 (compile task)
● Transpile to ES5 (Babel)
● Use ES5/ES6 polyfills (core-js)
● Babelify: opts.global or package.json
● Write ES6, publish ES5 (compile task)
● Babel - loose mode (es6.classes, es6.modules, … )
Takeaway
Thank you!
<3

More Related Content

PDF
ES2015 (ES6) Overview
PPTX
Modern JS with ES6
PDF
Effective ES6
PDF
Explaining ES6: JavaScript History and What is to Come
PDF
JavaScript - new features in ECMAScript 6
PDF
EcmaScript 6 - The future is here
PDF
An Intro To ES6
ODP
ES6 PPT FOR 2016
ES2015 (ES6) Overview
Modern JS with ES6
Effective ES6
Explaining ES6: JavaScript History and What is to Come
JavaScript - new features in ECMAScript 6
EcmaScript 6 - The future is here
An Intro To ES6
ES6 PPT FOR 2016

What's hot (20)

PPTX
Introduction to Ecmascript - ES6
PDF
Introduction into ES6 JavaScript.
PDF
JavaScript ES6
KEY
Alfresco the clojure way
ODP
Clojure: Practical functional approach on JVM
PDF
JavaScript and the AST
PPT
Developing iOS apps with Swift
PDF
Workshop 10: ECMAScript 6
PDF
A swift introduction to Swift
PPTX
iSoligorsk #3 2013
ZIP
Oral presentation v2
PDF
Introduction to Swift programming language.
PPTX
A Few Interesting Things in Apple's Swift Programming Language
PDF
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
PDF
Swift 2
PDF
Swift Programming Language
PDF
Swiftの関数型っぽい部分
PPTX
AST - the only true tool for building JavaScript
PDF
Introduction to clojure
PDF
Your code is not a string
Introduction to Ecmascript - ES6
Introduction into ES6 JavaScript.
JavaScript ES6
Alfresco the clojure way
Clojure: Practical functional approach on JVM
JavaScript and the AST
Developing iOS apps with Swift
Workshop 10: ECMAScript 6
A swift introduction to Swift
iSoligorsk #3 2013
Oral presentation v2
Introduction to Swift programming language.
A Few Interesting Things in Apple's Swift Programming Language
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
Swift 2
Swift Programming Language
Swiftの関数型っぽい部分
AST - the only true tool for building JavaScript
Introduction to clojure
Your code is not a string
Ad

Similar to ES6 in Production [JSConfUY2015] (20)

PDF
ES2015 workflows
PDF
A re introduction to webpack - reactfoo - mumbai
PDF
Ecmascript 2015 – best of new features()
PDF
Exploring ES6
PDF
Es6 modules-and-bundlers
PDF
ESCMAScript 6: Get Ready For The Future. Now
PDF
Advanced Debugging Using Java Bytecodes
PDF
Migrating Babel from CommonJS to ESM
PDF
Tamarin And Ecmascript 4
PDF
Tamarin and ECMAScript 4
PDF
ECMAScript 6
PDF
JavaScript Core
PPTX
A few good JavaScript development tools
KEY
Your Library Sucks, and why you should use it.
PDF
Painless Javascript Unit Testing
PPT
Practical Ext JS Debugging
PDF
Webpack: your final module bundler
PPT
Java introduction
PPTX
Es6 hackathon
PDF
JavaScript 1.5 to 2.0 (TomTom)
ES2015 workflows
A re introduction to webpack - reactfoo - mumbai
Ecmascript 2015 – best of new features()
Exploring ES6
Es6 modules-and-bundlers
ESCMAScript 6: Get Ready For The Future. Now
Advanced Debugging Using Java Bytecodes
Migrating Babel from CommonJS to ESM
Tamarin And Ecmascript 4
Tamarin and ECMAScript 4
ECMAScript 6
JavaScript Core
A few good JavaScript development tools
Your Library Sucks, and why you should use it.
Painless Javascript Unit Testing
Practical Ext JS Debugging
Webpack: your final module bundler
Java introduction
Es6 hackathon
JavaScript 1.5 to 2.0 (TomTom)
Ad

More from Guillermo Paz (7)

PDF
User First
PDF
Decoupling your JavaScript
PDF
HTML5: Introduction
PDF
JavaScript: The prototype Property
PDF
Estándares Web con Chico UI
PPT
Chico UI - Retreat 2011
PPT
Weat - Presentación
User First
Decoupling your JavaScript
HTML5: Introduction
JavaScript: The prototype Property
Estándares Web con Chico UI
Chico UI - Retreat 2011
Weat - Presentación

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Advanced IT Governance
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Machine learning based COVID-19 study performance prediction
PPTX
MYSQL Presentation for SQL database connectivity
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
KodekX | Application Modernization Development
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Per capita expenditure prediction using model stacking based on satellite ima...
Review of recent advances in non-invasive hemoglobin estimation
Advanced IT Governance
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
The AUB Centre for AI in Media Proposal.docx
Network Security Unit 5.pdf for BCA BBA.
Machine learning based COVID-19 study performance prediction
MYSQL Presentation for SQL database connectivity
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
KodekX | Application Modernization Development
GamePlan Trading System Review: Professional Trader's Honest Take
Unlocking AI with Model Context Protocol (MCP)
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

ES6 in Production [JSConfUY2015]