Goal: Build a math library that...
import { add, subtract } from 'math-lib';
let result = add(2, 3);
result = subtract(result, 4);
// In circle.js
const PI = Math.PI;
exports.area = (r) => PI * r * r; exports.circumference = (r) => 2 * PI * r;
// In some file
const circle = require('./circle.js');
console.log( `The area of a circle of radius 4 is ${circle.area(4)}`);
*Technically this is Node's take on CommonJS
//------ lib.js ------ export const sqrt = Math.sqrt; export function square(x) { return x * x; } export function diag(x, y) { return sqrt(square(x) + square(y)); } //------ main.js ------ import { square, diag } from 'lib'; console.log(square(11)); // 121 console.log(diag(4, 3)); // 5
Async import is Stage 3
Goal: Build a library
Note: This is where Rollup failed me in my own attempts at optimizing Stencil.