SlideShare a Scribd company logo
A Few Good JavaScript
Development Tools
Jul. 12 2016 Simon Kim
NexStreaming Corp.
Agenda
ECMAScript 6 - JavaScript Languages
Visual Studio Code - Editors or IDE
Node.js & npm - All Time Friends
webpack, Babel, UglifyJS - Build
Jasmine - Testing
Chrome Developer Tools - Debugging
YUIDoc - Documentation
Agenda
ECMAScript 6 - JavaScript Languages
Visual Studio Code - Editors or IDE
Node.js & npm - All Time Friends
webpack, Babel, UglifyJS - Build
Jasmine - Testing
Chrome Developer Tools - Debugging
YUIDoc - Documentation
Code
Build
Test
Debug
Document
Demo Project: https://github.com/simonkim/jstools-demo
JavaScript Language
ECMA-262 Specification
First Edition - June 1997
...
ECMAScript 5.1 Edition - June 2011
ECMAScript 6th Edition (ECMAScript 2015) - June 2015
ES6, ES2015
Misc.
CoffeeScript - http://coffeescript.org
JavaScript Language - ECMAScript 6
// ECMAScript 5
var Shape = function (id, x, y) {
this.id = id;
this.move(x, y);
};
Shape.prototype.move = function (x, y) {
this.x = x;
this.y = y;
};
// ECMAScript 6
class Shape {
constructor (id, x, y) {
this.id = id
this.move(x, y)
}
move (x, y) {
this.x = x
this.y = y
}
}
See http://es6-features.org for Details
Editors or IDEs
IDEs
WebStrom - JetBrains https://www.jetbrains.com/webstorm/ - $$$
Eclips IDE for JavaScript Web Developers - https://eclips.org - $$$
Aptana Studio 3 - http://www.aptana.com - $$$
Editors
Sublime Text - http://www.sublimetext.com - $
Atom - https://atom.io
Visual Studio Code - https://code.visualstudio.com/
Visual Studio Code
Node.js & npm
Node.js - https://nodejs.org/
JavaScript Runtime Built on Chrome’s V8 JavaScript Engine
Event Driven
Non-Blocking IO Model
npm - https://www.npmjs.com
Package Manager for JavaScript
Share and Reuse Node.js Modules
$ npm install express
# To publish
$ npm login
$ npm publish
npm - Example Node.js Module
See Using a package.json for Details
// package.json
{
"name": "mymodule",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified"
&& exit 1",
},
"author": "",
"license": "ISC"
}
// index.js
function Mymodule() {
}
Mymodule.prototype.hello = function() {
console.log(“Hello, Node.js module”);
}
module.exports = Mymodule;
// sample.js
Mymodule = require(‘./index’);
var mymodule = new MyModule();
mymodule.hello();
// Hello, Node.js module
Build
JavaScript is Interpreter Language, Why Build?
Bundle Multiple Modules into Single .JS File
<script src=”app.bundle.js” />
Transpile
Write in ES6, CoffeeScript, or TypeScript
Run Browser Compatible Version of JavaScript
Minimization and Obfuscation
The Smaller, The Faster Loading
Hard to Read Source
Build
GRUNT - http://gruntjs.com
A JavaScript task runner for automation configured in Gruntfile
gulp.js - http://gulpjs.com
Streaming build system runs tasks defined in gulpfile.js
Browserify - http://browserify.org
Bundle node modules to allow running in browsers
webpack - https://webpack.github.io
A module bundler: takes modules with dependencies and generates static assets
Build - webpack
Build - webpack
$ npm install webpack -g
$ webpack ./app.js app.bundle.js
http://webpack.github.io/docs/usage.html
Build - JavaScript in Web Browser
<body>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jque
ry.min.js"></script>
<div id="content">
<textarea id="input" rows=4 cols=80></textarea>
<button id="convert">Submit</button>
<p id="output"></p>
</div>
<script type="text/javascript">
$('#convert').click(function(e) {
var text = $('#input').val();
$( '#output' ).html( '<p>' + text + '</p>' );
});
</script>
</body>
Sample: https://jsfiddle.net/yd2517e4/
// webpack.config.js
module.exports = {
output.library: “Hlsm3u8”
}
Build - Node Module in Web Browser
<body>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jque
ry.min.js"></script>
<script src="scripts/app.bundle.js"></script>
<div id="content">
<textarea id="input" rows=4 cols=80></textarea>
<button id="convert">Submit</button>
<p id="output"></p>
</div>
<script type="text/javascript">
$('#convert').click(function(e) {
var text = $('#input').val();
var hlsm3u8 = new Hlsm3u8();
text = hlsm3u8.parse(text);
$( '#output' ).html( '<p>' + text + '</p>' );
});
</script>
</body>
‘output.library’ option of ‘webpack’
enables access to node module
exports from browser code
Build - Transpile
CoffeeScript - http://coffeescript.org
TypeScript - https://www.typescriptlang.org
Babel - https://babeljs.io
A JavaScript Compiler
ECPAScript 2015 ( ES6 ) to Browser Compatible JavaScript (? TBC)
// output.js
'use strict';
var _createClass = function () { //... }();
function _classCallCheck(instance, Constructor) { //... }
var Sample = function () {
function Sample(text) {
_classCallCheck(this, Sample);
this.text = text;
}
_createClass(Sample, [{
key: 'printHello',
value: function printHello() {
console.log('hello ' + this.text);
}
}]);
return Sample;
}();
var sample = new Sample('Babel');
sample.printHello();
Babel - Example
// sample.js
class Sample {
constructor(text) { this.text = text; }
printHello() { console.log(`hello ${this.text}`); }
}
var sample = new Sample('Babel');
sample.printHello();
// .babelrc
{
presets: [“es2015”]
}
# Install babel and transpile
$ npm install --save-dev babel-cli babel-preset-
es2015
$ ./node_modules/.bin/babel sample.js >
output.js
Build - Babel with webpack
Install Node Modules
$ npm install --save-dev babel-loader babel-core
Configure webpack
// webpack.config.js
module: {
loaders: [
{ test: /.js$/, exclude: /node_modules/, loader:
"babel-loader" }
]
}
Configure Babel: .babelrc
{
"presets": ["es2015"]
}
See https://babeljs.io/docs/setup/#installation for
Details
Build - Minimization and Obfuscation
minifier - https://www.npmjs.com/package/minifier
YUI Compressor - http://yui.github.io/yuicompressor/
UglifyJS2 - https://github.com/mishoo/UglifyJS2
Build - UglifyJS2 Example
# Install UglifyJS2
$ npm install uglify-js -g
$ uglifyjs input.js --compress --mangle -o
ouput.js
// output.js
"use strict";function _classCallCheck(e,n){if(!(e instanceof n))throw new
TypeError("Cannot call a class as a function")}var
_createClass=function(){function e(e,n){for(var t=0;t<n.length;t++){var
l=n[t];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in
l&&(l.writable=!0),Object.defineProperty(e,l.key,l)}}return
function(n,t,l){return
t&&e(n.prototype,t),l&&e(n,l),n}}(),Sample=function(){function
e(n){_classCallCheck(this,e),this.text=n}return
_createClass(e,[{key:"printHello",value:function(){console.log("hello
"+this.text)}}]),e}(),sample=new Sample("Babel");sample.printHello();
// input.js
'use strict';
var _createClass = function () { //... }();
function _classCallCheck(instance, Constructor) { //... }
var Sample = function () {
function Sample(text) {
_classCallCheck(this, Sample);
this.text = text;
}
_createClass(Sample, [{
key: 'printHello',
value: function printHello() {
console.log('hello ' + this.text);
}
}]);
return Sample;
}();
var sample = new Sample('Babel');
sample.printHello();
Build - UglifyJS with webpack
webpack UglifyJSPlugin
http://webpack.github.io/docs/list-of-
plugins.html#uglifyjsplugin
$ npm install webpack --save-dev
// webpack.config.js
module.exports = {
...
plugins:[new webpack.optimize.UglifyJsPlugin({
compress: {warnings: false},
})]
…
}
$ webpack
Testing
Jasmine - http://jasmine.github.io
“Jasmine is a behavior-driven development framework for testing JavaScript code.”
Karma - https://karma-runner.github.io/
Test Runner. Unit Testing.
And Many Others.
Testing - Jasmine
Install ‘jasmine’ command
$ npm install -g jasmine
Create jasmine.json, default
configuration
$ jasmine init
Write test cases, jasmine specs, and
run
$ jasmine
// myappSpec.js
describe("A suite", function() {
it("contains spec with an expectation",
function() {
expect(true).toBe(true);
});
it("The 'toBeLessThan' matcher is for
mathematical comparisons", function() {
var pi = 3.1415926,
e = 2.78;
expect(e).toBeLessThan(pi);
expect(pi).not.toBeLessThan(e);
});
});
Running Tests in a Browser
In HTML, include source and spec files and jasmine files
Open the HTML File in Browser
Testing - Jasmine
<link rel="shortcut icon" type="image/png"
href="lib/jasmine-2.4.1/jasmine_favicon.png">
<link rel="stylesheet" href="lib/jasmine-
2.4.1/jasmine.css">
<script src="lib/jasmine-
2.4.1/jasmine.js"></script>
<script src="lib/jasmine-2.4.1/jasmine-
html.js"></script>
<script src="lib/jasmine-
2.4.1/boot.js"></script>
<!-- include source files here... -->
<script
src="../public/dist/hlsm3u8.js"></script>
<!-- include spec files here... -->
<script
src="../spec/hlsm3u8spec.js"></script>
Chrome Developer Tools - https://developers.google.com/web/tools/chrome-devtools/
Chrome -> Menu -> View -> Developers -> Developer Tools
Source Map
Maps combined/minified file back to an unbuilt state
Debugging
Debugging - Chrome Developer Tools
Debugging - Source Map
Without Source Map
Debugging - Source Map
With Source Map
Debugging - Source Map
Introduction to JavaScript Source Map
Generating Source Map with webpack Build
$ webpack -d
app.bundle.js
app.bundle.js.map
See Development shortcut -d and devtool Webpack configuration for Details
Chrome DevTools Locates Source Map (.map) in the Same Path of .JS
Documentation
JSDoc - http://usejsdoc.org
Docco - https://jashkenas.github.io/docco/
YUIDoc - http://yui.github.io/yuidoc/
Documentation - YUIDoc
# Install babel and transpile
$ npm install -g yuidocjs
$ yuidoc .
$ # open out/index.html in browser
Summary
Code BuildTestDebug Document
+ Source Map
Demo Project:
https://github.com/simonkim/jstools-demo

More Related Content

KEY
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
KEY
Agile JavaScript Testing
PDF
System webpack-jspm
PDF
From Hacker to Programmer (w/ Webpack, Babel and React)
PDF
The JavaFX Ecosystem
PDF
Javascript Test Automation Workshop (21.08.2014)
PDF
Asynchronous Module Definition (AMD)
PDF
Thomas Fuchs Presentation
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Agile JavaScript Testing
System webpack-jspm
From Hacker to Programmer (w/ Webpack, Babel and React)
The JavaFX Ecosystem
Javascript Test Automation Workshop (21.08.2014)
Asynchronous Module Definition (AMD)
Thomas Fuchs Presentation

What's hot (20)

PPTX
Testing frontends with nightwatch & saucelabs
PDF
Django for mobile applications
KEY
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
PDF
20160905 - BrisJS - nightwatch testing
PDF
React Native in Production
PDF
Роман Лютиков "Web Apps Performance & JavaScript Compilers"
PDF
JavaFX – 10 things I love about you
PDF
The JavaFX Ecosystem
PDF
Metaprogramming 101
PDF
Building a Startup Stack with AngularJS
PDF
The DOM is a Mess @ Yahoo
PDF
Painless JavaScript Testing with Jest
PDF
JavaOne - The JavaFX Community and Ecosystem
PDF
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
PDF
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
PDF
From Swing to JavaFX
KEY
Testing JS with Jasmine
PDF
Vuejs testing
PPTX
Code ceptioninstallation
PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Testing frontends with nightwatch & saucelabs
Django for mobile applications
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
20160905 - BrisJS - nightwatch testing
React Native in Production
Роман Лютиков "Web Apps Performance & JavaScript Compilers"
JavaFX – 10 things I love about you
The JavaFX Ecosystem
Metaprogramming 101
Building a Startup Stack with AngularJS
The DOM is a Mess @ Yahoo
Painless JavaScript Testing with Jest
JavaOne - The JavaFX Community and Ecosystem
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
From Swing to JavaFX
Testing JS with Jasmine
Vuejs testing
Code ceptioninstallation
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Ad

Viewers also liked (7)

PDF
UglifyJS 使用文档
PDF
Debugging Javascript
PDF
Debugging tools in web browsers
PDF
Debugging JavaScript (by Thomas Bindzus, Founder, Vinagility & Thanh Loc Vo, ...
PDF
FITC - Here Be Dragons: Advanced JavaScript Debugging
KEY
Tools and Techniques for Faster Development
PDF
Finding and debugging memory leaks in JavaScript with Chrome DevTools
UglifyJS 使用文档
Debugging Javascript
Debugging tools in web browsers
Debugging JavaScript (by Thomas Bindzus, Founder, Vinagility & Thanh Loc Vo, ...
FITC - Here Be Dragons: Advanced JavaScript Debugging
Tools and Techniques for Faster Development
Finding and debugging memory leaks in JavaScript with Chrome DevTools
Ad

Similar to A few good JavaScript development tools (20)

PPTX
Angular JS in 2017
PDF
Modern javascript
PDF
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
PDF
PLOG - Modern Javascripting with Plone
PDF
Learning Nodejs For Net Developers Harry Cummings
PPTX
PHP Indonesia - Nodejs Web Development
PPTX
Irfan maulana nodejs web development
PDF
Building Enterprise Grade Front-End Applications with JavaScript Frameworks
PPTX
Next-generation JavaScript - OpenSlava 2014
PPTX
Js tacktalk team dev js testing performance
PDF
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
PPTX
SenchaCon 2016: The Modern Toolchain - Ross Gerbasi
PDF
Practical JavaScript Programming - Session 8/8
PDF
Ustream vs Legacy, It's never too late to start your fight! #Jsist 2014
PDF
Npm scripts
PDF
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
PDF
S&T What I know about Node 110817
PPT
Node js
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
DOCX
Brad Enterprise Solution Architect
Angular JS in 2017
Modern javascript
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
PLOG - Modern Javascripting with Plone
Learning Nodejs For Net Developers Harry Cummings
PHP Indonesia - Nodejs Web Development
Irfan maulana nodejs web development
Building Enterprise Grade Front-End Applications with JavaScript Frameworks
Next-generation JavaScript - OpenSlava 2014
Js tacktalk team dev js testing performance
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
SenchaCon 2016: The Modern Toolchain - Ross Gerbasi
Practical JavaScript Programming - Session 8/8
Ustream vs Legacy, It's never too late to start your fight! #Jsist 2014
Npm scripts
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
S&T What I know about Node 110817
Node js
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Brad Enterprise Solution Architect

Recently uploaded (20)

PPTX
Chapter----five---Resource Recovery.pptx
PDF
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
PDF
Introduction to Data Science: data science process
PPTX
Internship_Presentation_Final engineering.pptx
PDF
flutter Launcher Icons, Splash Screens & Fonts
PDF
Principles of Food Science and Nutritions
PPTX
Security-Responsibilities-in-the-Cloud-Azure-Shared-Responsibility-Model.pptx
PPTX
anatomy of limbus and anterior chamber .pptx
PPTX
meets orient on the new industry intereacting skills .pptx
PPTX
Simulation of electric circuit laws using tinkercad.pptx
PDF
Structs to JSON How Go Powers REST APIs.pdf
PDF
International Journal of Information Technology Convergence and Services (IJI...
PPT
SCOPE_~1- technology of green house and poyhouse
PDF
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
PDF
Top 10 read articles In Managing Information Technology.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Chapter----five---Resource Recovery.pptx
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
Introduction to Data Science: data science process
Internship_Presentation_Final engineering.pptx
flutter Launcher Icons, Splash Screens & Fonts
Principles of Food Science and Nutritions
Security-Responsibilities-in-the-Cloud-Azure-Shared-Responsibility-Model.pptx
anatomy of limbus and anterior chamber .pptx
meets orient on the new industry intereacting skills .pptx
Simulation of electric circuit laws using tinkercad.pptx
Structs to JSON How Go Powers REST APIs.pdf
International Journal of Information Technology Convergence and Services (IJI...
SCOPE_~1- technology of green house and poyhouse
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
Lesson 3_Tessellation.pptx finite Mathematics
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
Top 10 read articles In Managing Information Technology.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx

A few good JavaScript development tools

  • 1. A Few Good JavaScript Development Tools Jul. 12 2016 Simon Kim NexStreaming Corp.
  • 2. Agenda ECMAScript 6 - JavaScript Languages Visual Studio Code - Editors or IDE Node.js & npm - All Time Friends webpack, Babel, UglifyJS - Build Jasmine - Testing Chrome Developer Tools - Debugging YUIDoc - Documentation
  • 3. Agenda ECMAScript 6 - JavaScript Languages Visual Studio Code - Editors or IDE Node.js & npm - All Time Friends webpack, Babel, UglifyJS - Build Jasmine - Testing Chrome Developer Tools - Debugging YUIDoc - Documentation Code Build Test Debug Document Demo Project: https://github.com/simonkim/jstools-demo
  • 4. JavaScript Language ECMA-262 Specification First Edition - June 1997 ... ECMAScript 5.1 Edition - June 2011 ECMAScript 6th Edition (ECMAScript 2015) - June 2015 ES6, ES2015 Misc. CoffeeScript - http://coffeescript.org
  • 5. JavaScript Language - ECMAScript 6 // ECMAScript 5 var Shape = function (id, x, y) { this.id = id; this.move(x, y); }; Shape.prototype.move = function (x, y) { this.x = x; this.y = y; }; // ECMAScript 6 class Shape { constructor (id, x, y) { this.id = id this.move(x, y) } move (x, y) { this.x = x this.y = y } } See http://es6-features.org for Details
  • 6. Editors or IDEs IDEs WebStrom - JetBrains https://www.jetbrains.com/webstorm/ - $$$ Eclips IDE for JavaScript Web Developers - https://eclips.org - $$$ Aptana Studio 3 - http://www.aptana.com - $$$ Editors Sublime Text - http://www.sublimetext.com - $ Atom - https://atom.io Visual Studio Code - https://code.visualstudio.com/
  • 8. Node.js & npm Node.js - https://nodejs.org/ JavaScript Runtime Built on Chrome’s V8 JavaScript Engine Event Driven Non-Blocking IO Model npm - https://www.npmjs.com Package Manager for JavaScript Share and Reuse Node.js Modules $ npm install express
  • 9. # To publish $ npm login $ npm publish npm - Example Node.js Module See Using a package.json for Details // package.json { "name": "mymodule", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1", }, "author": "", "license": "ISC" } // index.js function Mymodule() { } Mymodule.prototype.hello = function() { console.log(“Hello, Node.js module”); } module.exports = Mymodule; // sample.js Mymodule = require(‘./index’); var mymodule = new MyModule(); mymodule.hello(); // Hello, Node.js module
  • 10. Build JavaScript is Interpreter Language, Why Build? Bundle Multiple Modules into Single .JS File <script src=”app.bundle.js” /> Transpile Write in ES6, CoffeeScript, or TypeScript Run Browser Compatible Version of JavaScript Minimization and Obfuscation The Smaller, The Faster Loading Hard to Read Source
  • 11. Build GRUNT - http://gruntjs.com A JavaScript task runner for automation configured in Gruntfile gulp.js - http://gulpjs.com Streaming build system runs tasks defined in gulpfile.js Browserify - http://browserify.org Bundle node modules to allow running in browsers webpack - https://webpack.github.io A module bundler: takes modules with dependencies and generates static assets
  • 13. Build - webpack $ npm install webpack -g $ webpack ./app.js app.bundle.js http://webpack.github.io/docs/usage.html
  • 14. Build - JavaScript in Web Browser <body> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jque ry.min.js"></script> <div id="content"> <textarea id="input" rows=4 cols=80></textarea> <button id="convert">Submit</button> <p id="output"></p> </div> <script type="text/javascript"> $('#convert').click(function(e) { var text = $('#input').val(); $( '#output' ).html( '<p>' + text + '</p>' ); }); </script> </body> Sample: https://jsfiddle.net/yd2517e4/
  • 15. // webpack.config.js module.exports = { output.library: “Hlsm3u8” } Build - Node Module in Web Browser <body> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jque ry.min.js"></script> <script src="scripts/app.bundle.js"></script> <div id="content"> <textarea id="input" rows=4 cols=80></textarea> <button id="convert">Submit</button> <p id="output"></p> </div> <script type="text/javascript"> $('#convert').click(function(e) { var text = $('#input').val(); var hlsm3u8 = new Hlsm3u8(); text = hlsm3u8.parse(text); $( '#output' ).html( '<p>' + text + '</p>' ); }); </script> </body> ‘output.library’ option of ‘webpack’ enables access to node module exports from browser code
  • 16. Build - Transpile CoffeeScript - http://coffeescript.org TypeScript - https://www.typescriptlang.org Babel - https://babeljs.io A JavaScript Compiler ECPAScript 2015 ( ES6 ) to Browser Compatible JavaScript (? TBC)
  • 17. // output.js 'use strict'; var _createClass = function () { //... }(); function _classCallCheck(instance, Constructor) { //... } var Sample = function () { function Sample(text) { _classCallCheck(this, Sample); this.text = text; } _createClass(Sample, [{ key: 'printHello', value: function printHello() { console.log('hello ' + this.text); } }]); return Sample; }(); var sample = new Sample('Babel'); sample.printHello(); Babel - Example // sample.js class Sample { constructor(text) { this.text = text; } printHello() { console.log(`hello ${this.text}`); } } var sample = new Sample('Babel'); sample.printHello(); // .babelrc { presets: [“es2015”] } # Install babel and transpile $ npm install --save-dev babel-cli babel-preset- es2015 $ ./node_modules/.bin/babel sample.js > output.js
  • 18. Build - Babel with webpack Install Node Modules $ npm install --save-dev babel-loader babel-core Configure webpack // webpack.config.js module: { loaders: [ { test: /.js$/, exclude: /node_modules/, loader: "babel-loader" } ] } Configure Babel: .babelrc { "presets": ["es2015"] } See https://babeljs.io/docs/setup/#installation for Details
  • 19. Build - Minimization and Obfuscation minifier - https://www.npmjs.com/package/minifier YUI Compressor - http://yui.github.io/yuicompressor/ UglifyJS2 - https://github.com/mishoo/UglifyJS2
  • 20. Build - UglifyJS2 Example # Install UglifyJS2 $ npm install uglify-js -g $ uglifyjs input.js --compress --mangle -o ouput.js // output.js "use strict";function _classCallCheck(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,n){for(var t=0;t<n.length;t++){var l=n[t];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(e,l.key,l)}}return function(n,t,l){return t&&e(n.prototype,t),l&&e(n,l),n}}(),Sample=function(){function e(n){_classCallCheck(this,e),this.text=n}return _createClass(e,[{key:"printHello",value:function(){console.log("hello "+this.text)}}]),e}(),sample=new Sample("Babel");sample.printHello(); // input.js 'use strict'; var _createClass = function () { //... }(); function _classCallCheck(instance, Constructor) { //... } var Sample = function () { function Sample(text) { _classCallCheck(this, Sample); this.text = text; } _createClass(Sample, [{ key: 'printHello', value: function printHello() { console.log('hello ' + this.text); } }]); return Sample; }(); var sample = new Sample('Babel'); sample.printHello();
  • 21. Build - UglifyJS with webpack webpack UglifyJSPlugin http://webpack.github.io/docs/list-of- plugins.html#uglifyjsplugin $ npm install webpack --save-dev // webpack.config.js module.exports = { ... plugins:[new webpack.optimize.UglifyJsPlugin({ compress: {warnings: false}, })] … } $ webpack
  • 22. Testing Jasmine - http://jasmine.github.io “Jasmine is a behavior-driven development framework for testing JavaScript code.” Karma - https://karma-runner.github.io/ Test Runner. Unit Testing. And Many Others.
  • 23. Testing - Jasmine Install ‘jasmine’ command $ npm install -g jasmine Create jasmine.json, default configuration $ jasmine init Write test cases, jasmine specs, and run $ jasmine // myappSpec.js describe("A suite", function() { it("contains spec with an expectation", function() { expect(true).toBe(true); }); it("The 'toBeLessThan' matcher is for mathematical comparisons", function() { var pi = 3.1415926, e = 2.78; expect(e).toBeLessThan(pi); expect(pi).not.toBeLessThan(e); }); });
  • 24. Running Tests in a Browser In HTML, include source and spec files and jasmine files Open the HTML File in Browser Testing - Jasmine <link rel="shortcut icon" type="image/png" href="lib/jasmine-2.4.1/jasmine_favicon.png"> <link rel="stylesheet" href="lib/jasmine- 2.4.1/jasmine.css"> <script src="lib/jasmine- 2.4.1/jasmine.js"></script> <script src="lib/jasmine-2.4.1/jasmine- html.js"></script> <script src="lib/jasmine- 2.4.1/boot.js"></script> <!-- include source files here... --> <script src="../public/dist/hlsm3u8.js"></script> <!-- include spec files here... --> <script src="../spec/hlsm3u8spec.js"></script>
  • 25. Chrome Developer Tools - https://developers.google.com/web/tools/chrome-devtools/ Chrome -> Menu -> View -> Developers -> Developer Tools Source Map Maps combined/minified file back to an unbuilt state Debugging
  • 26. Debugging - Chrome Developer Tools
  • 27. Debugging - Source Map Without Source Map
  • 28. Debugging - Source Map With Source Map
  • 29. Debugging - Source Map Introduction to JavaScript Source Map Generating Source Map with webpack Build $ webpack -d app.bundle.js app.bundle.js.map See Development shortcut -d and devtool Webpack configuration for Details Chrome DevTools Locates Source Map (.map) in the Same Path of .JS
  • 30. Documentation JSDoc - http://usejsdoc.org Docco - https://jashkenas.github.io/docco/ YUIDoc - http://yui.github.io/yuidoc/
  • 31. Documentation - YUIDoc # Install babel and transpile $ npm install -g yuidocjs $ yuidoc . $ # open out/index.html in browser
  • 32. Summary Code BuildTestDebug Document + Source Map Demo Project: https://github.com/simonkim/jstools-demo