requirejs commonjs与es6的import写法对比

require.js

首先定义:

//content.js

define('content.js', function(){

    return 'A cat';

})

然后require:

//index.js
require(['./content.js'], function(animal){

    console.log(animal);   //A cat

})

CommonJS

//index.js
var animal = require('./content.js')
//content.js
module.exports = 'A cat'

ES6的写法

//index.js
import animal from './content'
//content.js
export default 'A cat'

你可能感兴趣的:(requirejs commonjs与es6的import写法对比)