UNPKG

2.34 kBMarkdownView Raw
1# jiti
2
3> Runtime typescript and ESM support for Node.js (CommonJS)
4
5[![version][npm-v-src]][npm-v-href]
6[![downloads][npm-d-src]][npm-d-href]
7[![size][size-src]][size-href]
8
9## Features
10
11- Seamless typescript and ESM syntax support
12- Seamless interoperability between ESM and CommonJS
13- Synchronous API to replace `require`
14- Super slim and zero dependency
15- Smart syntax detection to avoid extra transforms
16- CommonJS cache integration
17- Filesystem transpile hard cache
18- V8 compile cache
19
20## Usage
21
22### Programmatic
23
24```js
25const jiti = require('jiti')(__filename)
26
27jiti('./path/to/file.ts')
28```
29
30You can also pass options as second argument:
31
32```js
33const jiti = require('jiti')(__filename, { debug: true })
34```
35
36### CLI
37
38```bash
39jiti index.ts
40# or npx jiti index.ts
41```
42
43### Register require hook
44
45```bash
46node -r jiti/register index.ts
47```
48
49Alternatively, you can register `jiti` as a require hook programmatically:
50```js
51const jiti = require('jiti')()
52const unregister = jiti.register()
53```
54
55## Options
56
57### `debug`
58
59- Type: Boolean
60- Default: `false`
61- Environment Variable: `JITI_DEBUG`
62
63Enable debug to see which files are transpiled
64
65### `cache`
66
67- Type: Boolean | String
68- Default: `true`
69- Environment Vriable: `JITI_CACHE`
70
71Use transpile cache
72
73If set to `true` will use `node_modules/.cache/jiti` (if exists) or `{TMP_DIR}/node-jiti`
74
75### `esmResolve`
76
77- Type: Boolean | String
78- Default: `false`
79- Environment Vriable: `JITI_ESM_RESOLVE`
80
81Using esm resolution algorithm to support `import` condition.
82
83### `transform`
84
85- Type: Function
86- Default: Babel (lazy loaded)
87
88Transform function. See [src/babel](./src/babel.ts) for more details
89
90## Development
91
92- Clone Repo
93- Run `yarn`
94- Run `yarn build`
95- Run `yarn dev`
96- Run `yarn jiti ./test/path/to/file.ts`
97
98## License
99
100MIT. Made with 💖
101
102<!-- Refs -->
103[npm-v-src]: https://img.shields.io/npm/v/jiti?style=flat-square
104[npm-v-href]: https://npmjs.com/package/jiti
105
106[npm-d-src]: https://img.shields.io/npm/dm/jiti?style=flat-square
107[npm-d-href]: https://npmjs.com/package/jiti
108
109[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/jiti/ci/master?style=flat-square
110[github-actions-href]: https://github.com/unjs/jiti/actions?query=workflow%3Aci
111
112[size-src]: https://packagephobia.now.sh/badge?p=jiti
113[size-href]: https://packagephobia.now.sh/result?p=jiti