版博士V2.0程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

README.md 3.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. # jiti
  2. > Runtime typescript and ESM support for Node.js
  3. [![version][npm-v-src]][npm-v-href]
  4. [![downloads][npm-d-src]][npm-d-href]
  5. [![size][size-src]][size-href]
  6. ## Features
  7. - Seamless typescript and ESM syntax support
  8. - Seamless interoperability between ESM and CommonJS
  9. - Synchronous API to replace `require`
  10. - Super slim and zero dependency
  11. - Smart syntax detection to avoid extra transforms
  12. - CommonJS cache integration
  13. - Filesystem transpile hard cache
  14. - V8 compile cache
  15. - Custom resolve alias
  16. ## Usage
  17. ### Programmatic
  18. ```js
  19. const jiti = require("jiti")(__filename);
  20. jiti("./path/to/file.ts");
  21. ```
  22. You can also pass options as second argument:
  23. ```js
  24. const jiti = require("jiti")(__filename, { debug: true });
  25. ```
  26. ### CLI
  27. ```bash
  28. jiti index.ts
  29. # or npx jiti index.ts
  30. ```
  31. ### Register require hook
  32. ```bash
  33. node -r jiti/register index.ts
  34. ```
  35. Alternatively, you can register `jiti` as a require hook programmatically:
  36. ```js
  37. const jiti = require("jiti")();
  38. const unregister = jiti.register();
  39. ```
  40. ## Options
  41. ### `debug`
  42. - Type: Boolean
  43. - Default: `false`
  44. - Environment Variable: `JITI_DEBUG`
  45. Enable debug to see which files are transpiled
  46. ### `cache`
  47. - Type: Boolean | String
  48. - Default: `true`
  49. - Environment Variable: `JITI_CACHE`
  50. Use transpile cache
  51. If set to `true` will use `node_modules/.cache/jiti` (if exists) or `{TMP_DIR}/node-jiti`
  52. ### `esmResolve`
  53. - Type: Boolean | String
  54. - Default: `false`
  55. - Environment Variable: `JITI_ESM_RESOLVE`
  56. Using esm resolution algorithm to support `import` condition.
  57. ### `transform`
  58. - Type: Function
  59. - Default: Babel (lazy loaded)
  60. Transform function. See [src/babel](./src/babel.ts) for more details
  61. ### `sourceMaps`
  62. - Type: Boolean
  63. - Default `false`
  64. - Environment Variable: `JITI_SOURCE_MAPS`
  65. Add inline source map to transformed source for better debugging.
  66. ### `interopDefault`
  67. - Type: Boolean
  68. - Default: `false`
  69. Return the `.default` export of a module at the top-level.
  70. ### `alias`
  71. - Type: Object
  72. - Default: -
  73. - Environment Variable: `JITI_ALIAS`
  74. Custom alias map used to resolve ids.
  75. ### `nativeModules`
  76. - Type: Array
  77. - Default: ['typescript`]
  78. - Environment Variable: `JITI_NATIVE_MODULES`
  79. List of modules (within `node_modules`) to always use native require for them.
  80. ### `transformModules`
  81. - Type: Array
  82. - Default: []
  83. - Environment Variable: `JITI_TRANSFORM_MODULES`
  84. List of modules (within `node_modules`) to transform them regardless of syntax.
  85. ## Development
  86. - Clone this repository
  87. - Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
  88. - Install dependencies using `pnpm install`
  89. - Run `pnpm dev`
  90. - Run `pnpm jiti ./test/path/to/file.ts`
  91. ## License
  92. MIT. Made with 💖
  93. <!-- Refs -->
  94. [npm-v-src]: https://img.shields.io/npm/v/jiti?style=flat-square
  95. [npm-v-href]: https://npmjs.com/package/jiti
  96. [npm-d-src]: https://img.shields.io/npm/dm/jiti?style=flat-square
  97. [npm-d-href]: https://npmjs.com/package/jiti
  98. [github-actions-src]: https://img.shields.io/github/workflow/status/unjs/jiti/ci/master?style=flat-square
  99. [github-actions-href]: https://github.com/unjs/jiti/actions?query=workflow%3Aci
  100. [size-src]: https://packagephobia.now.sh/badge?p=jiti
  101. [size-href]: https://packagephobia.now.sh/result?p=jiti