ES6 specification

A single export

/ / export
export let name1 = 'zhangsan';
export let name2 = 'lisi';

/ / import
import {name1, name2} from './test.js';
Copy the code

The batch export

/ / export
let name1 = 'zhangsan';
let name2 = 'lisi';
let name3 = 'wangwu';
export {name1, name2, name3}

/ / import
import {name1, name2, name3} from './test.js';
Copy the code

Take the alias

/ / export
let name1 = 'zhangsan';
let name2 = 'lisi';
let name3 = 'wangwu';
export {name1 as n1, name2 as n2, name3 as n3}

/ / import
import * as name from './test.js';
Copy the code

A module can only have one default export. For the default export, the name of the import can be different from the name of the export

/ / export
export default function(){
    console.log('Default export');
}

/ / import
import func from './test.mjs';
func();
Copy the code
/ / export
export default {
    func(){
        console.log('Default export');
    },
    name:'zhangsan'.age:22
}

/ / import
import obj from './a.mjs';

obj.func();
console.log(obj.name);
console.log(obj.age);
Copy the code

CommonJS specification

/ / export
module.exports.name = 'zhangsan'
module.exports.age = 'zhangsan'
module.exports.func = function(){ console.log('commonJS standard')}/ / import
const  obj = require('./a');

console.log(obj.name);
console.log(obj.age);
obj.func();

/ / or
const { name, age, func } = require('./a');

console.log(name);
console.log(age);
func();

Copy the code