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

Load ES6 Modules Like a Boss with SystemJS and ...

Load ES6 Modules Like a Boss with SystemJS and JSPM

The ES6 JavaScript standard brings modules to the masses, but the process of bundling and delivering those modules in today’s browsers still requires a separate loader. Learn how SystemJS was built from scratch to support this format, and how JSPM will change the way you manage your code.

Avatar for Aaron Ladage

Aaron Ladage

August 03, 2017

Other Decks in Technology

Transcript

  1. HISTORY OF JAVASCRIPT ▸ Created by Brendan Eich at Netscape

    ▸ Written in 10 days in May 1995 ▸ Included with Netscape Navigator 2.0 JS isn’t as old as you think it is (or maybe I’m just old)
  2. PROBLEMS WITH EARLY JAVASCRIPT JavaScript’s usage outpaced its original implementation

    ▸ Render blocking ▸ Can lead to excessive HTTP requests ▸ Lacking: ▸ Namespacing (global pollution) ▸ Modularity ▸ Dependency management
  3. EARLY SOLUTIONS Global object / IIFE ▸ More of an

    exploit than a standard ▸ Still exposes a global variable ▸ Still easily overwritten ▸ Load order matters ▸ Sharing code between objects is challenging
  4. EARLY SOLUTIONS CommonJS ▸ Doesn’t work well in async environments

    ▸ Lazy loading is a challenge ▸ Requires an external loader
  5. EARLY SOLUTIONS AMD/Require ▸ Ugly syntax ▸ Async, but can’t

    be statically analyzed ▸ Still requires an external loader
  6. ES6 But there’s one big problem… ▸ The ES6 spec

    defined the module format, but it didn’t define a loader ▸ Not yet implemented in all browsers ▸ Spawned the ES Module Loader project (and polyfill)
  7. SYSTEMJS Universal module loader ▸ Supports common, AMD, global object

    and ES6 ▸ Can handle Coffee/TypeScript (and even CSS) with plugins ▸ Built on top of the ES6 module loader polyfill ▸ Can run client or server-side (Node) ▸ Lazy-loads JS bundles
  8. SYSTEMJS A relatively uncomplicated API on its own ▸ Can

    do runtime transpiling during development ▸ SystemJS builder can bundle
  9. JSPM The ultimate JavaScript package manager ▸ You’ve heard that

    before…but this time, it might be true ▸ …if you’re using SystemJS, that is ▸ Companion project to SystemJS
  10. JSPM “Why don’t you just use NPM?” JSPM is equal

    parts package manager, loader and bundler
  11. JSPM As a package manager ▸ CLI tool ▸ Install

    third-party modules from GitHub or NPM via command line
  12. JSPM As a package manager ▸ Auto-configs SystemJS loader config

    file ▸ Registries ▸ Semi-official JSPM registry ▸ Roll your own! (DEGJS)
  13. JSPM As a loader (during development) ▸ Uses SystemJS module

    loader ▸ Transpile and import on the fly during dev ▸ Useful, but can get slow
  14. PITFALLS SystemJS/JSPM are pretty good, but they aren’t perfect ▸

    Tricky configuration ▸ Skeletor ▸ Trial and error with third-party config
  15. PITFALLS SystemJS/JSPM are pretty good, but they aren’t perfect ▸

    Created and largely maintained
 by one British gentleman ▸ Smaller community ▸ Slower updates (Not actually Guy Bedford)
  16. IN CONCLUSION Everyone loves a summary slide! ▸ JavaScript quickly

    outgrew its original intent and implementation ▸ Developers are clever and found solutions, each with its own shortcomings ▸ ES6 modules standardizes JS modules, but there’s no well-supported native loading (yet) ▸ SystemJS bridges the gap as a universal loader ▸ JSPM serves as equal parts package manager, loader and bundler ▸ SystemJS/JSPM together aren’t perfect…but they’re pretty damn good.
  17. RESOURCES ▸ "Understanding ES6 Modules Via Their History" ▸ “Brief

    History of JavaScript Modules” ▸ SystemJS project ▸ JSPM project ▸ Skeletor ▸ DEGJS