[question]could this package be used to wrap local files?
Opened this issue · 3 comments
radiorz commented
Like I have a Test.js file,
could i change it like this:
const path = require("path");
const { Hook } = require("require-in-the-middle");
// Hook into the Test module
new Hook(["./Test.js"], function (exports, name, basedir) {
// 在这里对Test模块进行修改或扩展
console.log("Hooked into Test module:", name);
// 返回你想要的修改后的exports对象
return exports;
});
const Test = require("./Test.js");
console.log(`Test`, Test);
radiorz commented
I find absolute path is work:
const Hook = require("require-in-the-middle");
// Hook into the Test module
const hook = new Hook(["G:\\xxx\\math\\require_hack\\Test.js"], function (
exports,
name,
basedir
) {
// 在这里对Test模块进行修改或扩展
console.log("Hooked into module:", name);
// 返回你想要的修改后的exports对象
return exports;
});
const Test = require("./Test");
but it doesnt work when using null or ['./Test.js']