Upgrade to Pro — share decks privately, control downloads, hide ads and more …

comparing module bundler for the browser

comparing module bundler for the browser

Show why you should use a package manager and the difference between browserify, component and duo
// EDIT
Realized that webpack is a really good solution, prefer webpack over component and duo!

Avatar for Anton Wilhelm

Anton Wilhelm

November 13, 2014
Tweet

More Decks by Anton Wilhelm

Other Decks in Technology

Transcript

  1. Agenda - Agony of choice - What do package managers

    do? - Why should you use a package manager? - How to write modularized applications - Application Manifest & how to load modules - How to compare all the Frontend Package Managers
  2. 1. install dependencies ! 2. bundle your app for the

    browser What do package managers do?
  3. - install dependencies - transitive dependencies - javascript - css

    - images, fonts What do package managers do?
  4. - build your app for the browser - provide a

    module loader - bundle dependencies & your app code - make images, fonts available What do package managers do?
  5. you don’t want to install all the dependencies (incl. transitive)

    by hand Why should you use a package manager?
  6. <script src="bower_components/todomvc-common/base.js"></script>! <script src="js/helpers.js"></script>! <script src="js/store.js"></script>! <script src="js/model.js"></script>! <script src="js/template.js"></script>!

    <script src="js/view.js"></script>! <script src="js/controller.js"></script>! <script src="js/app.js"></script> /*global qs, qsa, $on, $parent, $live */! ! (function (window) { ! ………………………………………………………………………………………………………………………………………………………………………………………………! // Export to window ! window.app = window.app || {}; ! window.app.View = View; ! }(window));!
  7. TodoMVC - Vanilla JavaScript Example - handling all the files

    in the right order - dependency management via window ! → it doesn’t scale with more dependencies
  8. semantic versioning • X-Ranges 1.2.x 1.X 1.2.* * ! •

    Tilde Ranges ~1.2.3 ~1.2 ~1 ! • Caret Ranges ^1.2.3 ^0.2.5 ^0.0.4
  9. .! !"# component/classes 1.2.1! $ %"" component/indexof 0.0.3! %"# component/reactive

    1.2.0! !"" component/query 0.0.1! !"" component/emitter 1.1.1! !"# component/classes 1.1.1! $ %"" component/indexof 0.0.3! !"" component/event 0.1.0! !"" component/domify 1.2.1! !"# yields/carry 0.0.1! $ !"# component/classes 1.2.2! $ $ %"" component/indexof 0.0.3! $ !"" yields/merge-attrs 0.0.1! $ %"# yields/uniq 1.0.0! $ %"" component/indexof 0.0.1! %"" visionmedia/debug 0.7.4 why semantic versioning is important for the frontend
  10. - self-contained modules - easy to test - fast to

    build - transparent to refactor local dependencies
  11. - define entry point(s) and lookup path in the root

    manifest - define local & remote dependencies in each module - avoid ../.. to get out of the local module how to achieve local dependencies
  12. real world example – DemocracyOS ./lib! !"" 404! !"" accepts!

    !"" admin! !"" admin-laws! !"" admin-laws-form! !"" admin-sidebar! !"" admin-tags! !"" admin-tags-form! !"" api! !"" auth! !"" autosubmit! !"" autovalidate! !"" balance! !"" body-classes! !"" boot! !"" browser-lock! !"" build! !"" citizen! !"" comment! !"" comments-edit! !"" comments-filter! !"" comments-replies! !"" comments-replies-edit! !"" comments-view! !"" layout! !"" logout! !"" mailer! !"" markdown! !"" models! !"" participants-view! !"" proposal! !"" proposal-article! !"" proposal-clauses! !"" proposal-options! !"" regexps! !"" render! !"" request! !"" rss! !"" settings! !"" settings-api! !"" settings-password! !"" settings-profile! !"" setup! !"" side-comments! !"" sidebar! !"" signin! !"" signin-api! !"" signup! !"" signup-api! !"" comments-view! !"" config! !"" content-lock! !"" db-api! !"" delegation! !"" facebook-card! !"" feedback! !"" fixtures! !"" flaticons! !"" forgot! !"" forgot-api! !"" form-view! !"" header! !"" help! !"" help-faq! !"" help-glossary! !"" help-markdown! !"" help-pp! !"" help-tos! !"" homepage! !"" is-mobile! !"" law! !"" law-api! !"" laws! !"" laws-filter! !"" snapper! !"" stateful! !"" stateful-view! !"" stats-api! !"" store! !"" tag! !"" tag-images! !"" tags! !"" title! !"" translations! !"" twitter-card! !"" user-badge! !"" utils! !"" validate! !"" validators! %"" view
  13. component/todo application .! !"" index.html! !"" <manifest> (root manifest)! %""

    lib! !"" boot! $ !"" <manifest>! $ !"" index.js! $ %"" style.css! !"" item! $ !"" <manifest>! $ %"" index.js! %"" item-presenter! !"" <manifest! !"" index.js! !"" style.css! %"" template.html
  14. package manager root manifest local manifest "dependencies": { "boot": "file:./lib/boot",

    } "dependencies": { "item": "file:../item", "item-presenter": "file:../item-presenter" } "locals": [ "boot" ], "paths": [ "lib" ] "locals": [ "item" "item-presenter" ] $ duo lib/boot/index.{js,css} manifest configuration
  15. loading modules require('domify')! require('item')! require('./script') require('domify')! require('component-domify')! require('component require('item')! require('./script')

    require('component/domify' require(' require('component/domify:index.js') require('/lib/item')! require('./script') remote dependency local dependency relative file (within a module)
  16. package manager local deps remote deps properties browserify implicit via

    .main (package.json) explicit (package.json) .main .dependencies component explicit (component.json) explicit (component.json) .main! .scripts! .styles .locals . duo implicit via command line implicit manifest formats
  17. implicit - no update is needed if a new file

    was added or removed - need to touch the code to update and refactor remote dependencies explicit - central overview - faster build - orphan deps - boilerplate implicit vs. explicit
  18. TodoFPM modernizr but for package managers TodoMVC but for modularized

    structure + compare all the Frontend Package Manager
  19. TodoFPM - auto-generated feature matrix - semantic versioning - source

    maps - module loader - example app (Todo) - see which features are provided to write modular software - handling css, images and fonts compare all the Frontend Package Manager