Skip to content

Commit 46cdad6

Browse files
committed
Update documentation
1 parent 9571a61 commit 46cdad6

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

readme.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# require-precompiled
22

3-
> Require extension that allows for caching/precompiling
4-
3+
Modifies `require()` so you can load precompiled module sources.
54

65
## Install
76

87
```
98
$ npm install --save require-precompiled
109
```
1110

12-
1311
## Usage
1412

1513
```js
@@ -28,17 +26,24 @@ installPrecompiler(filename => {
2826
const foo = require('some-module');
2927
```
3028

31-
3229
## API
3330

34-
### requirePrecompiled(callback)
35-
36-
#### callback
31+
```ts
32+
function installPrecompiler(
33+
loadSource: (filename: string) => string | null,
34+
ext = '.js',
35+
): void
36+
```
3737

38-
Type: `Function(string: filename)`
38+
The `loadSource()` function should return a source string when a precompiled source is available. Return `null` to fall back to Node.js' default behavior.
3939

40-
Return `string` contents for a cache hit, or `null` for a miss.
40+
By default the precompiler is installed for `.js` files. You can specify alternative extensions by providing the second argument:
4141

42+
```js
43+
installPrecompiler(filename => {
44+
// ...
45+
}, '.cjs')
46+
```
4247

4348
## License
4449

0 commit comments

Comments
 (0)