Modify the source of an imported module
$ npm install --save import-modify
// greet.js
module.exports = () => {
console.log('hello');
};
const importModify = require('import-modify');
const greet = importModify('./greet', source => {
return source.replace('hello', 'yo');
});
greet();
//=> 'yo'
// greet.js
const greet = () => {
console.log('hello');
};
const importModify = require('import-modify');
const greet = importModify('./greet', source => {
return `${source}\nmodule.exports = greet;`;
});
greet();
//=> 'hello'
Type: string
Same as you would use in require()
.
Type: function
Function where you modify the source and return the new one.
MIT © Sindre Sorhus