swc-node
Ajude-me a me tornar um desenvolvedor de código aberto em tempo integral, patrocinando-me no Github
Transformador TypeScript/JavaScript
rápido sem node-gyp
e script postinstall .
Execute TypeScript com nó, sem compilação ou verificação de digitação:
npm i -D @swc-node/register
node -r @swc-node/register script.ts
node --import @swc-node/register/esm-register script.ts # for esm project with node>=20.6
node --loader @swc-node/register/esm script.ts # for esm project with node<=20.5, deprecated
Passe --enable-source-maps
para o nó para projetos ESM
Defina a variável de ambiente SWCRC = true quando desejar carregar o arquivo .swcrc
SWCRC=true node -r @swc-node/register script.ts
#!/usr/bin/env -S node --import @swc-node/register/esm-register
// your code
execute com shebang, adicione TS_NODE_PROJECT=null
( #!/usr/bin/env TS_NODE_PROJECT=null node --import @swc-node/register/esm-register
) para usar ignore tsconfig.json
Transformador TypeScript
mais rápido.
Detalhe: @swc-node/core
transforme RxJS
AjaxObservable.ts
em ES2015 e CommonJSJavaScript
. Código de referência: banco
Informações de hardware :
Model Name: MacBook Pro
Model Identifier: MacBookPro15,1
Processor Name: 6-Core Intel Core i7
Processor Speed: 2.6 GHz
Number of Processors: 1
Total Number of Cores: 6
L2 Cache (per Core): 256 KB
L3 Cache: 12 MB
Hyper-Threading Technology: Enabled
Memory: 16 GB
transformSync
esbuild x 510 ops/sec ±1.28% (88 runs sampled)
@swc-node/core x 438 ops/sec ±1.00% (88 runs sampled)
typescript x 28.83 ops/sec ±10.20% (52 runs sampled)
babel x 24.21 ops/sec ±10.66% (46 runs sampled)
Transform rxjs/AjaxObservable.ts benchmark bench suite: Fastest is esbuild
transform
paralelo UV_THREADPOOL_SIZE=11 yarn bench
@swc-node/core x 1,253 ops/sec ±0.90% (75 runs sampled)
esbuild x 914 ops/sec ±1.31% (77 runs sampled)
Transform rxjs/AjaxObservable.ts parallel benchmark bench suite: Fastest is @swc-node/core
yarn bench
@swc-node/core x 1,123 ops/sec ±0.95% (77 runs sampled)
esbuild x 847 ops/sec ±3.74% (71 runs sampled)
Transform rxjs/AjaxObservable.ts parallel benchmark bench suite: Fastest is @swc-node/core
O transformador TypeScript
mais rápido.
Detalhe: @swc-node/jest
Testando em projeto
TypeScript
puro, o destino de compilação éES2018
. Executando comnpx jest --no-cache
,ts-jest
foi configurado comisolatedModules: true
Test Suites: 49 passed, 49 total
Tests: 254 passed, 254 total
Snapshots: 53 passed, 53 total
Time: 54.631 s
Ran all test suites.
Done in 62.71s.
Test Suites: 49 passed, 49 total
Tests: 254 passed, 254 total
Snapshots: 53 passed, 53 total
Time: 10.511 s
Ran all test suites.
Done in 14.34s.
Alternativa mais rápida ts-node/register/transpile-only
.
Detalhe: @swc-node/register
pnpm i
pnpm build
pnpm test