Top Banner
SYSTEM, WEBPACK, & JSPM JESSE WARDEN | RVA.JS | NOV 3 2015
45

System webpack-jspm

Apr 12, 2017

Download

Documents

Jesse Warden
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: System webpack-jspm

SYSTEM, WEBPACK, & JSPMJESSE WARDEN | RVA.JS | NOV 3 2015

Page 2: System webpack-jspm

TEXT

WHAT?

▸ DevOps & Lean Engineering

▸ Brief on Angular/React/Backbone & Node Workflow

▸ Deep Dive in JavaScript Modules

Page 3: System webpack-jspm

JAVASCRIPTMODULES

Page 4: System webpack-jspm

WINDOW

GLOBAL

▸ In the beginning… there was window

Page 5: System webpack-jspm

NO SCALE

GLOBAL BAD

▸ global variables: they fast…

▸ … but no clue who’s setting them, access control

▸ global state

▸ no control

Page 6: System webpack-jspm

<SCRIPT SRC>

EXTERNAL FILES

▸ load via block

▸ parse

▸ "run"

Page 7: System webpack-jspm

EXTERNAL

A.JS VS. B.JS

Page 8: System webpack-jspm

YOU SHOULDN’T WRITE ‘EM

SCRIPT PROBLEMS

▸ order issue

▸ flat dependency != tree

Page 9: System webpack-jspm

NODE

COMMONJS

▸ Encapsulation / Global Safe (unless you r t3h l@m3 and use global)

▸ Module system

▸ Version Safe (via local node_modules)

▸ synchronous

▸ dependent loading

▸ Node (server or build system)

Page 10: System webpack-jspm

NODE

COMMONJS

Page 11: System webpack-jspm

BROWSER

REQUIRE.JS

▸ asynchronous

▸ different than <script defer>

▸ back when "pages" vs. "views" or "components" nomenclature

▸ CDN hosted libs

▸ "load on the fly"

▸ minor dependency injection

▸ build via r.js

Page 12: System webpack-jspm

EXAMPLE

REQUIRE.JS

Page 13: System webpack-jspm

BUILD

GRUNT / GULP

▸ Angular (ok)

▸ Manual Dependency Ordering (insane, no scale)

Page 14: System webpack-jspm

REQUIRE IN THE BROWSER

BROWSERIFY

▸ "work everywhere"

▸ Node rocks with CommonJS, let’s use it

▸ "universal JavaScript"

▸ i.e. lodash

▸ build system, not runtime

▸ supports bundles (atomify, cssify, tsify)

▸ https://github.com/substack/browserify-handbook

Page 15: System webpack-jspm

REQUIRE IN THE BROWSER

BROWSERIFY

Page 16: System webpack-jspm

REQUIRE IN THE BROWSER

BROWSERIFY

Page 17: System webpack-jspm

REQUIRE IN THE BROWSER

BROWSERIFY

▸ static analysis (uses detective)

▸ creates Abstract Syntax Tree (AST)

Page 18: System webpack-jspm

REQUIRE IN THE BROWSER

BROWSERIFY

▸ injectable

▸ hot replace

▸ via beefy, wzrd, browserify-middleware, etc.

Page 19: System webpack-jspm

REQUIRE IN THE BROWSER

BROWSERIFY

Page 20: System webpack-jspm

REQUIRE IN THE BROWSER

BROWSERIFY

▸ built in classes for Node in the browser

▸ transforms (CoffeeScript, TypeScript, CSS, images, etc)

▸ customizable browser fallback

Page 21: System webpack-jspm

NEW JS

ES6

▸ ECMAScript 2015

▸ No one calls it that except for standards people

▸ OOP: Yay, classes!

▸ Functional: Yay, new features!

▸ DevOps: Yay, static dependency tree!

▸ http://exploringjs.com/es6/ch_modules.html

Page 22: System webpack-jspm

EXAMPLE

ES6

Page 23: System webpack-jspm

EXAMPLE

ES6

Page 24: System webpack-jspm

EXAMPLE

ES6

Page 25: System webpack-jspm

EXAMPLE

ES6

Scripts ModulesHTML <script> <script type="module">

Top-Level variables are global local to moduleValue of this at top level window undefined

Executed sync asyncimport statement no yes

Promise-based API yes yesFile extension .js .js

Page 26: System webpack-jspm

OTHER BENEFITS

ES6

▸ better cyclic dependencies

▸ module renaming on consumer

▸ import { name1 as localName1, name2 } from ‘src/my_lib';

▸ static initializer

▸ import 'src/my_lib';

Page 27: System webpack-jspm

LOADER OF EVERYTHING

WEBPACK

▸ better Require.js

▸ more features / API’s than Browserify

▸ built in vs. plugins/3rd party

▸ does that matter…?

▸ … only for ES6

▸ … AND RUNTIME

▸ https://webpack.github.io/

Page 28: System webpack-jspm

LOADER OF EVERYTHING

WEBPACK

Page 29: System webpack-jspm

LOADER OF EVERYTHING

WEBPACK

Page 30: System webpack-jspm

LOADER OF EVERYTHING

WEBPACK

▸ bundle it

Page 31: System webpack-jspm

LOADER OF EVERYTHING

WEBPACK

▸ npm install webpack-dev-server -g

▸ webpack-dev-server —progress —colors

▸ Code Splitting: http://webpack.github.io/docs/code-splitting.html

Page 32: System webpack-jspm

LEVEL 1: BOILERPLATE

ES6-MODULE-LOADER

▸ programmatically work with modules

▸ configure module loading

▸ Loader: NOT part of the standard

▸ System: NOT part of the standard

▸ … both are expected to be

▸ https://github.com/ModuleLoader/es6-module-loader

Page 33: System webpack-jspm

SPECIFICS

ES6-MODULE-LOADER

▸ Provides System.import

▸ Runtime, not build time

▸ Assumes Traceur, Babel, or TypeScript

▸ ES6 circular refs

▸ paths

▸ [show basic]

Page 34: System webpack-jspm

SPECIFICS

ES6-MODULE-LOADER

Page 35: System webpack-jspm

SPECIFICS

ES6-MODULE-LOADER

Page 36: System webpack-jspm

LEVEL 2: FOR USAGE

SYSTEMJS

▸ Built on ES6-Module-Loader

▸ loads any module format (CommonJS, AMD, ES5, ES6, None)

▸ Supports RequireJS-style maps, paths, shims, etc.

▸ Loader plugin works with CSS, JSON, and Images

▸ Browser + Node

▸ Gallons of plugins like Browserify & Webpack have

Page 37: System webpack-jspm

LEVEL 2: FOR USAGE

SYSTEMJS

▸ Zebra Striping

▸ Modules

▸ Standalone

Page 38: System webpack-jspm

LEVEL 2: BROWSER

SYSTEMJS

Page 39: System webpack-jspm

LEVEL 2: NODE

SYSTEMJS

Page 40: System webpack-jspm

LEVEL 3: ALL YOU NEED

JSPM

▸ package manager for SystemJS

▸ called ES6 module loader (but you know better)

▸ loads from npm and Github

▸ dev == load, prod == standalone (or load)

▸ CLI for installing; use jspm instead of npm

▸ global registry

▸ http://jspm.io/

Page 41: System webpack-jspm

LEVEL 3: ALL YOU NEED

JSPM

▸ npm should work out of the box

▸ NodeJS libs for Browser are same as Browserify

▸ GitHub version is semvar

▸ package.json by default, or overridden by you

▸ flattens dependencies

Page 42: System webpack-jspm

LEVEL 3: ALL YOU NEED

JSPM

▸ improves package.js with new tags

Page 43: System webpack-jspm

LEVEL 3: ALL YOU NEED

JSPM

▸ standalone (production)

Page 44: System webpack-jspm

DONE.

CONCLUSIONS

▸ JSPM should be all you need

▸ Will probably be standard

▸ Runtime + Build time

▸ All 3 libraries built-on top of each other

▸ supports 3 languages and all module formats

Page 45: System webpack-jspm

THANKS!

JESSE WARDEN

▸ @jesterxl

[email protected]

▸ https://www.youtube.com/user/jesterxl

▸ http://jessewarden.com/blog/