modulesbackspaces.net/temp/modules.pdf · not part of es2015 this is left as implementation-defined...

19
Taming Modules ECMA: Module Syntax/Semantics WHATWG: Module Loaders

Upload: others

Post on 21-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

Taming ModulesECMA: Module Syntax/Semantics

WHATWG: Module Loaders

Page 2: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

Browser: Global Modules

<script src = ‘lib/firebase.js'></script>

<script src = 'http://cdn/jquery.js'></script>

Page 3: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

Node/NPM: require()

var gulp = require('gulp');

var concat = require('gulp-concat');

Page 4: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

Module Systems: Legacy & ES6

• Legacy:

• Global

• CommonJS

• AMD

• ES6:

• System

Huge incompatibility / interoperability problem

Page 5: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's
Page 6: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

ES6 Import

Page 7: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

ES6 Export

Page 8: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

But No Module Loaders!

Babel:

Page 9: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

What a mess!

• NPM: Browserify, Babelify

• RequireJS

• WebPack

• JSPM

• Bundling

• Transpiling

• .. and more

Page 10: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

Standards Track, Whew

• The System Object

Page 11: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

Github: System Polyfill

Page 12: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

The System Object

• Mainly importing: (Transitive Closure)

Page 13: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

And a bit more

Page 14: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

Simple: Goal

Page 15: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

Solution

• Babel:

• babel-cli

• babel-plugin-transform-es2015-modules-systemjs

• System: Download or NPM install

• App: <script src="system.js"></script> .. and <script> System.import('lib/main'); </script>

Page 16: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

Test

• main:

• square:

• sqrt:

Page 17: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

Babel: main

Page 18: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

Babel: square

Page 19: Modulesbackspaces.net/temp/Modules.pdf · Not part of ES2015 This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's

Babel: sqrt