0%

nodejs-CommonJS和ECMAScript

require

1
2
3
4
5
6
7
8
9
10
//opt.js
module.exports = {
add,del
};

module.exports.a = a;


//main.js
const {add, del,a} = require('./opt')

import

1
2
3
4
5
//addTwo.mjs
export { addTwo };

//main.js
import { addTwo } from './addTwo.mjs';