Skip to content

Module Systems

Xiaohan Zhang edited this page Mar 14, 2017 · 1 revision

Module systems

  1. commonjs - require() and exports =
  2. nodejs - same as commonjs except module.exports = is the actual variable they look at (and they alias exports to module.exports)
  3. AMD - define(["dep1"], function(dep1) {...})
    1. async capable
  4. ES2015 Modules - import { } from "foo"; export var k = ...
    1. Browsers don't support yet
  5. Global export - window.foo = ..., and you add scripts in the correct order

Things that operate on module systems

  1. Typescript - same as ES2015 module syntax, and then you specify "module": commonjs, amd, systemjs, etc in the tsconfig.json; Typescript converts the ES2015 module syntax into the other module system that you've specified
  2. UMD - a piece of code you put at the beginning of your file to convert commonjs, AMD, or global export to work with each other
  3. Systemjs - some new thing that supports everything...?

Things that implement module systems

  1. webpack/browserify - Can work with all of the module systems to create one js file that runs on the web
  2. require.js - an AMD only loader; you reference it in your webpage and it does the async loading of all the modules
  3. node.js - runs code specified in the nodejs module system (obviously)

Plottable support

Plottable 3.0 and later:

  • Is written in ES2015 module syntax with Typescript
  • Compiles and ships commonjs modules in its /build folder on npm
  • Compiles a single UMD module at plottable.js