swc node
@swc-node
swc-node
在 Github 上贊助我,幫助我成為全職開源開發人員
無需node-gyp
和安裝後腳本的快速TypeScript/JavaScript
轉換器。
使用節點執行 TypeScript,無需編譯或類型檢查:
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
將--enable-source-maps
傳遞給 esm 專案的節點
當您想要載入 .swcrc 檔案時,設定環境變數 SWCRC=true
SWCRC=true node -r @swc-node/register script.ts
#!/usr/bin/env -S node --import @swc-node/register/esm-register
// your code
使用 shebang 運行,新增TS_NODE_PROJECT=null
( #!/usr/bin/env TS_NODE_PROJECT=null node --import @swc-node/register/esm-register
) 以使用ignore tsconfig.json
最快的TypeScript
轉換器。
詳細資料:@swc-node/core
將 RxJS
AjaxObservable.ts
轉換為 ES2015 和 CommonJSJavaScript
。基準碼:bench
硬體資訊:
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
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
最快的笑話TypeScript
轉換器。
詳細資訊:@swc-node/jest
在純
TypeScript
專案中測試,編譯目標是ES2018
。使用npx jest --no-cache
運行,ts-jest
配置為isolatedModules: 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.
更快的ts-node/register/transpile-only
替代方案。
詳細資訊:@swc-node/register
pnpm i
pnpm build
pnpm test