amd,cmd,umd,commonjs,esmodule

各个模块使用场景及其导入导出基本语法,让你看一眼代码就知道这是什么类型模块。

AMD

使用场景:require.js,浏览器端,异步加载模块
导入语句:

require(['module-name'], function (module) { 
// 使用module 
});

导出语句:

define(['dependency1', 'dependency2'], function (dep1, dep2) {
  return {
    export1: value1,
    export2: value2
  };
});

CMD

使用场景:sea.js,服务器端,同步加载模块
导入语句:

const module = require('module-name');

导出语句:

define(function (require, exports, module) {
  const export1 = value1;
  const export2 = value2;
}

UMD

使用场景:commonjs+amd+环境变量,既可以跑在node环境,也可以浏览器环境
环境判断语句:

(function(global,factory) {
  typeof module!=='undefined'&& typeof exports==='object'?module.exports=factory():
  typeof define==='function' && define.amd ? define(factory):
  (global = global || self,global.Sortable = factory())
}(this,(function(){'use strict'}))
)

commonJs

使用场景:常用于node.js后台开发
导入语句:

const a = require('lodash');

​​​导出语句

module.exports = 变量名;

esMoudle

使用场景:前端日常开发(react,vue)
导入语句:

import a from 'A';

导出语句

export default A;
export {
  A,
  b
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值