Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 438 Bytes

README.md

File metadata and controls

19 lines (15 loc) · 438 Bytes

shim-require

Pre-process javascript files as they get required

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" }