Namespace Imports
Import everything a module exports as a namespace object using * as name. Access exports as properties of that object.
Import everything a module exports as a namespace object using * as name. Access exports as properties of that object.
// math.js exports: PI, add, subtract, multiply
import * as Math from "./math.js";
console.log(Math.PI); // 3.14159
console.log(Math.add(2, 3)); // 5
console.log(Math.multiply(2, 4)); // 8
// Useful when you need many exports
// or when there is a name conflict
Namespace imports disable tree-shaking for that module — prefer named imports when possible for better bundling.
More in JavaScript