同步加载
模块 JS
function show(content) {
window.document.getElementById("app").innerText = "Hello," + content;
}
// 通过 CommonJS 规范导出 show 函数
module.exports = show;
main.js 中引入
import show from "./show";
show("webpack");
bundle.js
(function (modules) {
...
function __webpack_require__(moduleId) {
...
var module = (installedModules[moduleId] =
exports: {
},
});
// 执行对应模块函数,并且传入需要的参数
modules[moduleId].call(
module.exports,
module,
module.exports,
__webpack_require__
);
// 返回这个模块的导出值
return module.exports