JS: Static Import

By Xah Lee. Date: . Last updated: .

(new in JS: ECMAScript 2015)

Import Syntax for Default Export

import newName from modulePath;

import the default export value at modulePath and name it newName in your source code.

Import Syntax for Named Export

import { name1 , name2 … } from modulePath;

Import a list of exported names. (Each of the name must be explicited exported by the module.)

import { name1 as new1 … } from modulePath;

Import a list of exported names with new alias. Your code access the imported symbols by their new name, e.g. new1

import * as newName from modulePath;

Get all exported names from modulePath, attach to newName as properties.

Load Module

This will just load module:

import modulePath;

JavaScript. Module Import Export