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
|
25 | const jiti = require('jiti')(__filename)
|
26 |
|
27 | jiti('./path/to/file.ts')
|
28 | ```
|
29 |
|
30 | You can also pass options as second argument:
|
31 |
|
32 | ```js
|
33 | const jiti = require('jiti')(__filename, { debug: true })
|
34 | ```
|
35 |
|
36 | ### CLI
|
37 |
|
38 | ```bash
|
39 | jiti index.ts
|
40 | # or npx jiti index.ts
|
41 | ```
|
42 |
|
43 | ### Register require hook
|
44 |
|
45 | ```bash
|
46 | node -r jiti/register index.ts
|
47 | ```
|
48 |
|
49 | Alternatively, you can register `jiti` as a require hook programmatically:
|
50 | ```js
|
51 | const jiti = require('jiti')()
|
52 | const unregister = jiti.register()
|
53 | ```
|
54 |
|
55 | ## Options
|
56 |
|
57 | ### `debug`
|
58 |
|
59 | - Type: Boolean
|
60 | - Default: `false`
|
61 | - Environment Variable: `JITI_DEBUG`
|
62 |
|
63 | Enable debug to see which files are transpiled
|
64 |
|
65 | ### `cache`
|
66 |
|
67 | - Type: Boolean | String
|
68 | - Default: `true`
|
69 | - Environment Vriable: `JITI_CACHE`
|
70 |
|
71 | Use transpile cache
|
72 |
|
73 | If set to `true` will use `node_modules/.cache/jiti` (if exists) or `{TMP_DIR}/node-jiti`
|
74 |
|
75 | ### `transform`
|
76 |
|
77 | - Type: Function
|
78 | - Default: Babel (lazy loaded)
|
79 |
|
80 | Transform function. See [src/babel](./src/babel.ts) for more details
|
81 |
|
82 | ## Development
|
83 |
|
84 | - Clone Repo
|
85 | - Run `yarn`
|
86 | - Run `yarn build`
|
87 | - Run `yarn dev`
|
88 | - Run `yarn jiti ./test/path/to/file.ts`
|
89 |
|
90 | ## License
|
91 |
|
92 | MIT. Made with 💖
|
93 |
|
94 |
|
95 | [npm-v-src]: https://img.shields.io/npm/v/jiti?style=flat-square
|
96 | [npm-v-href]: https://npmjs.com/package/jiti
|
97 |
|
98 | [npm-d-src]: https://img.shields.io/npm/dm/jiti?style=flat-square
|
99 | [npm-d-href]: https://npmjs.com/package/jiti
|
100 |
|
101 | [github-actions-src]: https://img.shields.io/github/workflow/status/unjs/jiti/ci/master?style=flat-square
|
102 | [github-actions-href]: https://github.com/unjs/jiti/actions?query=workflow%3Aci
|
103 |
|
104 | [size-src]: https://packagephobia.now.sh/badge?p=jiti
|
105 | [size-href]: https://packagephobia.now.sh/result?p=jiti
|