1 | # `create-require`
|
2 |
|
3 | [![npm version][npm-version-src]][npm-version-href]
|
4 | [![npm downloads][npm-downloads-src]][npm-downloads-href]
|
5 | [![Github Actions][github-actions-src]][github-actions-href]
|
6 | [![Codecov][codecov-src]][codecov-href]
|
7 |
|
8 | Polyfill for Node.js [`module.createRequire`](https://nodejs.org/api/modules.html#modules_module_createrequire_filename) (<= v12.2.0)
|
9 |
|
10 | ## Install
|
11 |
|
12 | ```sh
|
13 | yarn add create-require
|
14 |
|
15 | npm install create-require
|
16 | ```
|
17 |
|
18 | ## Usage
|
19 |
|
20 | ```ts
|
21 | function createRequire (filename: string | URL): NodeRequire;
|
22 | ```
|
23 |
|
24 | ```js
|
25 | const createRequire = require('create-require')
|
26 |
|
27 | const myRequire = createRequire('path/to/test.js')
|
28 | const myModule = myRequire('./test-sibling-module')
|
29 | ```
|
30 |
|
31 | ## License
|
32 |
|
33 | [MIT](./LICENSE)
|
34 |
|
35 |
|
36 | [npm-version-src]: https://img.shields.io/npm/v/create-require?style=flat-square
|
37 | [npm-version-href]: https://npmjs.com/package/create-require
|
38 |
|
39 | [npm-downloads-src]: https://img.shields.io/npm/dm/create-require?style=flat-square
|
40 | [npm-downloads-href]: https://npmjs.com/package/create-require
|
41 |
|
42 | [github-actions-src]: https://img.shields.io/github/workflow/status/nuxt-contrib/create-require/test/master?style=flat-square
|
43 | [github-actions-href]: https://github.com/nuxt-contrib/create-require/actions?query=workflow%3Atest
|
44 |
|
45 | [codecov-src]: https://img.shields.io/codecov/c/gh/nuxt-contrib/create-require/master?style=flat-square
|
46 | [codecov-href]: https://codecov.io/gh/nuxt-contrib/create-require
|