Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fijimunkii/node-shim-require

Pre-process javascript files as they get required
https://github.com/fijimunkii/node-shim-require

compile instrumentation optimize pre-process preprocess process require shim source

Last synced: 28 days ago
JSON representation

Pre-process javascript files as they get required

Awesome Lists containing this project

README

        

# shim-require

Pre-process javascript files as they get `require`d

```js
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
```js
shimRequire(content => content.replace(/foo/g, 'bar'), 'json');
require('foo.json'); // { "a": "bar" }
```