Modules
      10.1 Always use modules (import/export) over a non-standard module system.
      10.2 Do not use wildcard imports.
      10.6 In modules with a single export, prefer default export over named export.
        Interpretation: multiple exports allowed
    Confusing as hell
      ESM vs CommonJS vs ES6
If using export default use import var from module:
1
export const foo = 42
2
export default 21;
Copied!
If you want the 21, use import bar from './input';
1
import barImport from './input';
2
console.log(barImport); // 21
3
4
const barRequire = require('./input');
5
console.log(barRequire);
6
/*
7
{
8
foo: 42,
9
default: 21,
10
}
11
*/
Copied!

Notes

1
export const types = () => {}
Copied!
is different from
1
export function types() { }
Copied!

Clearing Confusing

Goals
CommonJs
module.exports = ...
var module = require('module')
AMD
define(['dependency1'], function(dependency1
Load synchronously
Asynchronous Module Definition
UMD
Universal Module Definition
ESM

Last modified 2yr ago
Copy link
Contents