module.exports require与exports属于CommonJS模块规范
export default属于ES6模块规范
javascript
module.exports.x = x;
let x = require('./x.js');
12
Node为每个模块提供一个exports变量,指向module.exports。这等同在每个模块头部,有一行这样的命令:
javascript
var exports = module.exports;
1
profile.js
javascript
var firstName = 'Michael';
var lastName = 'Jackson';
var year = 1958;
export {firstName, lastName, year};
import { year } from './profile.js'
123456
// 写法一
javascript
export var m = 1;
1
// 写法二
javascript
var m = 1;
export {m};
12
// 写法三
javascript
var n = 1;
export {n as m};
12
评论 (0)