经过前面非模块化和AMD打包的例子,本节我们就不再绕圈子,直接看例子。
HTML代码和之前仍然是一样的,不再重复,JS文件如下:
入口文件example1.1.js
:
var example2 = require('./example1.2');
example2.sayHello();
被依赖的example1.2.js
:
var me = {
sayHello:function(){
alert('hello world!');
}
};
module.exports = me;
同样使用webpack编译就能看到相同的弹窗。