shim-require
v1.0.0
Published
Pre-process javascript files as they get `require`d
Downloads
22
Maintainers
Readme
shim-require
Pre-process javascript files as they get require
d
const shimRequire = require('shim-require');
shimRequire((content, filename) => {
// return modified content
return `console.log("loading ${filename}");\n${content}`;
});
require('foo'); // `loading /path/to/foo`
Can also modify json files
shimRequire(content => content.replace(/foo/g, 'bar'), 'json');
require('foo.json'); // { "a": "bar" }