UNPKG

2.62 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 Variable: `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 Variable: `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### `sourceMaps`
91
92- Type: Boolean
93- Default `false`
94- Environment Variable: `JITI_SOURCE_MAPS`
95
96Add inline source map to transformed source for better debugging.
97
98### `interopDefault`
99
100- Type: Boolean
101- Default: `false`
102
103Return the `.default` export of a module at the top-level.
104
105## Development
106
107- Clone Repo
108- Run `yarn`
109- Run `yarn build`
110- Run `yarn dev`
111- Run `yarn jiti ./test/path/to/file.ts`
112
113## License
114
115MIT. Made with 💖
116
117<!-- Refs -->
118[npm-v-src]: https://img.shields.io/npm/v/jiti?style=flat-square
119[npm-v-href]: https://npmjs.com/package/jiti
120
121[npm-d-src]: https://img.shields.io/npm/dm/jiti?style=flat-square
122[npm-d-href]: https://npmjs.com/package/jiti
123
124[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/jiti/ci/master?style=flat-square
125[github-actions-href]: https://github.com/unjs/jiti/actions?query=workflow%3Aci
126
127[size-src]: https://packagephobia.now.sh/badge?p=jiti
128[size-href]: https://packagephobia.now.sh/result?p=jiti