ES6模块化(module)简介

2018-01-11  本文已影响0人  ITgecko

前言

CommonJS 和 AMD

let fs = require('fs')
let bodyParser = require('body-parser')
let app = new (require('express'))()

export命令

var b = 456
export var a = 123;
export b
export function c () {
  return 789
}
var n = 1;
export {n as m};

import

import { a, b, c } from './target.js';
import {method as newName} from 'util';
import { foo } from 'my_module';
import { bar } from 'my_module';
// 等同于,并且只会引入一个my_module实例
import { foo, bar } from 'my_module';
import *
import * as fullPack from './target.js'
console.log(fullPack.a, fullPack.b, fullPack.c)

export default

// 比如在使用vue开发时,每个component用export default输出自身,其他地方再用import引入
export default {
  // 一些代码
}
// 路由文件
import target from './components/target'
结语
上一篇 下一篇

猜你喜欢

热点阅读