手写webpack (3)
2021-04-03 08:24
标签:source tput 输出 打开 join code 笔记 通过 dev 手写webpack (3) 标签:source tput 输出 打开 join code 笔记 通过 dev 原文地址:https://www.cnblogs.com/guangzhou11/p/12543068.html emitFile() {
// 打包输出的路径
let main = path.join(this.config.output.path, this.config.output.filename)
console.log(main, ‘test‘)
this.assets = {}
//
let templateStr = this.getSource(path.join(__dirname, ‘main.ejs‘));
let code = ejs.render(templateStr, { entryId: this.entryId, modules: this.modules })
//路径对应的代码
this.assets[main] = code;
fs.writeFileSync(main, this.assets[main])
}
(function(modules) {
var installedModules = {};
function __webpack_require__(moduleId) {
if(installedModules[moduleId]) {
return installedModules[moduleId].exports;
}
var module = installedModules[moduleId] = {
i: moduleId,
l: false,
exports: {}
};
modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
module.l = true;
return module.exports;
}
return __webpack_require__(__webpack_require__.s = "");
})
/* 自执行函数 传入参数 */
({
"":
(function(module, exports, __webpack_require__) {
eval(``);
}),
});