Transcript
Page 1: Front End Dependency Management at CascadiaJS

FRONT END DEPENDENCYMANAGEMENT

LET'S HUG IT OUT, FRIENDSPresented to you by / Joe Sepi @joe_sepi

Page 2: Front End Dependency Management at CascadiaJS

I AM WHO I THINK I AM.VP of Engineering at where we do financialanalysis awesomelyPreviously worked at doing dev, devmgmt and dev relationsI also consider myself something of a

on the twitter machine

Novus.com

The New York Times

punk@joe_sepi

Page 3: Front End Dependency Management at CascadiaJS

Rene Auberjonois

Page 4: Front End Dependency Management at CascadiaJS

WE'RE ALL IN THIS TOGETHER

Page 5: Front End Dependency Management at CascadiaJS

HISTORYDojo, Modules/Transport/C, RunJS, Narwhal, etc...

Page 6: Front End Dependency Management at CascadiaJS

WHAT ARE THE PROBLEMS WE ARE TRYING TOSOLVE?

<script src="..."></script><script src="..."></script><script src="..."></script><script MyApp.something.whatever.gone.too.far('fail');this must load before that but not before

Page 7: Front End Dependency Management at CascadiaJS

So those are the problems we are trying to solve, but what arethe benefits of solving these problems?

performance, stability, sanity, reuse,

Page 8: Front End Dependency Management at CascadiaJS

HOW DO WE GET THERE?

ModulesTooling

Bonus: Repository

Page 9: Front End Dependency Management at CascadiaJS

PLEASE DON'T SKIN THE CAT

Page 10: Front End Dependency Management at CascadiaJS

AMD, RequireJS, Bower--

CommonJS, Browserify, NPM

Page 11: Front End Dependency Management at CascadiaJS

How do we use these tools to actually solve this problem?

Page 12: Front End Dependency Management at CascadiaJS

REQUIRE

Page 13: Front End Dependency Management at CascadiaJS

INDEX.HTML<script data-main="js/main" src="js/require.js"></script>

MAIN.JSrequire(['beep', 'boop'], function(beep, boop) { beep(); boop();});

BEEP.JSdefine(['robot'], function(robot) { var speak = function () { robot('beep'); }; return speak;});

ROBOT.JSdefine(function() { return function (s) { return console.log(s.toUpperCase() + '!'); };});

Page 14: Front End Dependency Management at CascadiaJS

BROWSERIFY

Page 15: Front End Dependency Management at CascadiaJS

IN TERMINAL$ browserify main.js > bundle.js

INDEX.HTML<script src="js/bundle.js"></script>

MAIN.JSvar beep = require('beep');var boop = require('boop');beep();boop();

BEEP.JSvar robot = require('robot');var speak = function () { robot('beep');};module.exports = speak;

ROBOT.JSmodule.exports = function (s) { return console.log(s.toUpperCase() + '!');};

Page 16: Front End Dependency Management at CascadiaJS

BEEP + ROBOT?? - USING MODULE.EXPORTS OBJECTvar robot = require('robot');var speak = function () { robot('beep');};var dance = function () { $('body').append('<img src="dancing-bender.gif">');};module.exports = { speak : speak, dance : dance}

Page 17: Front End Dependency Management at CascadiaJS

BEEP + ROBOT?? - USING EXPORTS.WHATEVSvar robot = require('robot');exports.speak = function () { robot('beep');};exports.dance = function () { $('body').append('<img src="dancing-bender.gif">');};

Page 18: Front End Dependency Management at CascadiaJS

BEEP + ROBOT?? - USING REQ WITH HYBRID PATTERNdefine(function(require, exports, module) { var robot = require('robot'); exports.speak = function () { robot('beep'); }; exports.dance = function () { $('body').append('<img src="dancing-bender.gif">'); };});

Page 19: Front End Dependency Management at CascadiaJS

BACKBONE VIEWdefine([ 'jquery', 'underscore', 'backbone', 'text!templates/example.html'], function ($, _, Backbone, exampleTemplate) { var AppView = Backbone.View.extend({ el: '#main', template: _.template(exampleTemplate), render: function () { this.$el.html(this.template({})); return this; } });

return AppView;});

Page 20: Front End Dependency Management at CascadiaJS

BACKBONE VIEWdefine(function (require, exports, module) { var $ = require('jquery'); var _ = require('underscore'); var Backbone = require('backbone'); var exampleTemplate = require('text!templates/example.html');

var AppView = Backbone.View.extend({ el: '#main', template: _.template(exampleTemplate), render: function () { this.$el.html(this.template({})); return this; } });

return AppView;});

Page 21: Front End Dependency Management at CascadiaJS

HERE ARE THE WAYS IN WHICH EACHAPPROACH SHINES:

Page 22: Front End Dependency Management at CascadiaJS

REQUIRE BIG WIN:ASYNC MODULE LOAD

dive in quicklydebug loaded deps in console

dynamically load code

Page 23: Front End Dependency Management at CascadiaJS

BROWSERIFY BIG WIN(S):npm install [module-name] --saveserver and browser code share

through bundling (and transforms) you can do most anything

Page 24: Front End Dependency Management at CascadiaJS

AMD, RequireJS, Bowervs

CommonJS, Browserify, NPM

Page 25: Front End Dependency Management at CascadiaJS

WHAT ABOUT ES6 MODULES?WILL THEY SAVE US FROM OURSELVES AND SOLVE WORLD HUNGER?

I'm glad you asked!

Page 26: Front End Dependency Management at CascadiaJS

IN CONCLUSIONDo what feels right

Come talk to me about what you think I missed or am missing

Page 27: Front End Dependency Management at CascadiaJS

THE ENDPresented to you by / Joe Sepi @joe_sepi


Top Related