$ cnpm install jiti
Runtime typescript and ESM support for Node.js (CommonJS)
const jiti = require('jiti')(__filename)
jiti('./path/to/file.ts')
You can also pass options as second argument:
const jiti = require('jiti')(__filename, { debug: true })
debug
false
JITI_DEBUG
Enable debug to see which files are transpiled
cache
true
JITI_CACHE
Use transpile cache
If set to true
will use node_modules/.cache/jiti
(if exists) or {TMP_DIR}/node-jiti
transform
Transform function. See src/babel for more details
standard-things/esm
+
Much more stable thanks to babel+
Less low level operations+
Typescript support-
Slower (without cache)babel-register
+
Smaller install size (~1M vs ~11M with same plugins)+
Configured out of the box+
Smart syntax detect to avoid unnecessary trnaspilation+
Does not ignores node_modules
. ESM everywhere yay!+
Embeddableesbuild
+
No native dependency+
More stable thanks to babel-
Slower+
Embeddablets-node
+
Support both esm and typescript/
No typechecking support / Faster+
Smart syntax detect to avoid unnecessary transpilation.mjs
files with different executation context (no __filename
, require
, etc)rollup
, webpack
, snowpack
, etc)Meanwhile it would be much better making an optimized bundle to deploy to production or as npm package, using bundler setup and watching is frustrating during project development that's where jiti
(or similar tools like ts-node
) would be more convenient.
Note: However currently only babel transform is supported, configurable transform support is in the roadmap so using esbuild
or other solutions would be possible.
yarn
yarn build
yarn dev
node ./test/jiti.js
node -r jiti
MIT. Made with ????
Copyright 2014 - 2016 © taobao.org |