npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tsconfig-swc

v1.0.0

Published

Translate a tsconfig JSON object into a swcrc JSON object.

Readme

tsconfig-swc

Translate a tsconfig JSON object into a swcrc JSON object with comprehensive mapping support.

  • Comprehensive mapping: Supports most TypeScript compiler options
  • JSX support: Full React JSX transformation configuration
  • Decorators: Experimental decorators and metadata support
  • Path mapping: baseUrl and paths configuration
  • Source maps: Complete source map configuration
  • Module systems: CommonJS, ES6, AMD, UMD support
  • Type-safe: Full TypeScript type definitions

Installation

npm install tsconfig-swc

Usage

import convert from "tsconfig-swc";

const tsconfig = {
  compilerOptions: {
    target: "ES2020",
    module: "CommonJS",
    jsx: "ReactJSX",
    experimentalDecorators: true,
    sourceMap: true,
  },
};

const swcConfig = convert(tsconfig);
console.log(swcConfig); // SWC configuration object

Configuration Mapping

This table shows how TypeScript compiler options map to SWC configuration options:

Core Compilation Options

| TSConfig Option | SWC Equivalent | Notes | | --------------- | ------------------- | ---------------------------------------------------------- | | target | jsc.target | Maps ES versions (ES5 → es5, ES2020 → es2020, etc.) | | module | module.type | Maps module systems (CommonJS → commonjs, ES6 → es6, etc.) | | lib | N/A | Handle via environment/polyfills, not SWC | | allowJs | jsc.parser.syntax | Influences syntax detection | | checkJs | N/A | TypeScript-only feature |

JSX Configuration

| TSConfig Option | SWC Equivalent | Notes | | -------------------- | ----------------------------------------------- | ------------------------------------------------------ | | jsx | jsc.parser.jsx, jsc.transform.react.runtime | Maps JSX modes (React → classic, ReactJSX → automatic) | | jsxFactory | jsc.transform.react.pragma | React pragma function | | jsxFragmentFactory | jsc.transform.react.pragmaFrag | React fragment pragma | | jsxImportSource | jsc.transform.react.importSource | Import source for automatic runtime |

Decorators & Experimental Features

| TSConfig Option | SWC Equivalent | Notes | | ------------------------- | -------------------------------------------------------- | ----------------------------------- | | experimentalDecorators | jsc.parser.decorators, jsc.transform.legacyDecorator | Enables decorator support | | emitDecoratorMetadata | jsc.transform.decoratorMetadata | Decorator metadata emission | | useDefineForClassFields | jsc.transform.useDefineForClassFields | Class field initialization behavior |

Module Resolution & Paths

| TSConfig Option | SWC Equivalent | Notes | | ------------------ | -------------- | ------------------------------ | | baseUrl | jsc.baseUrl | Base URL for path resolution | | paths | jsc.paths | Path mapping configuration | | moduleResolution | N/A | Handled by bundler/environment | | typeRoots | N/A | TypeScript-only feature | | types | N/A | TypeScript-only feature |

Module Interop & Imports

| TSConfig Option | SWC Equivalent | Notes | | ------------------------------ | ------------------ | ----------------------------------------------------------- | | esModuleInterop | module.noInterop | Inverted mapping (esModuleInterop: false → noInterop: true) | | allowSyntheticDefaultImports | N/A | Handled by module system | | resolveJsonModule | N/A | Handled by bundler | | preserveSymlinks | N/A | Handled by module resolver |

Source Maps & Output

| TSConfig Option | SWC Equivalent | Notes | | ----------------- | ------------------------- | -------------------------------------------------------------------- | | sourceMap | sourceMaps: true | External source maps | | inlineSourceMap | sourceMaps: 'inline' | Inline source maps | | inlineSources | inlineSourcesContent | Include source content in maps | | removeComments | jsc.preserveAllComments | Inverted mapping (removeComments: false → preserveAllComments: true) |

Helpers & Optimization

| TSConfig Option | SWC Equivalent | Notes | | -------------------- | ------------------------------------ | ----------------------------------- | | importHelpers | jsc.externalHelpers | Use external helper functions | | downlevelIteration | N/A | SWC handles iteration automatically | | preserveConstEnums | jsc.transform.treatConstEnumAsEnum | Const enum behavior |

TypeScript-Only Options

These options are TypeScript compiler-specific and have no SWC equivalent:

| TSConfig Option | Notes | | ---------------------------------- | --------------------------------------------------- | | declaration | Type declaration generation (use tsc for this) | | declarationMap | Declaration source maps (use tsc for this) | | emitDeclarationOnly | Declaration-only compilation (use tsc for this) | | outDir | Output directory (handled by build tools) | | outFile | Single file output (use bundler) | | rootDir | Root directory (handled by build tools) | | noEmit | No emit mode (use tsc --noEmit for type checking) | | strict | Type checking option, not compilation | | noImplicitAny | Type checking option, not compilation | | strictNullChecks | Type checking option, not compilation | | strictFunctionTypes | Type checking option, not compilation | | noImplicitReturns | Type checking option, not compilation | | noFallthroughCasesInSwitch | Type checking option, not compilation | | skipLibCheck | TypeScript-only optimization | | forceConsistentCasingInFileNames | TypeScript-only file system check |

Examples

Node.js Project

// tsconfig.json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "CommonJS",
    "strict": true,
    "esModuleInterop": true,
    "sourceMap": true,
    "outDir": "dist"
  }
}

// Generated .swcrc
{
  "$schema": "https://swc.rs/schema.json",
  "jsc": {
    "parser": { "syntax": "typescript" },
    "target": "es2020"
  },
  "module": {
    "type": "commonjs",
    "strict": true
  },
  "sourceMaps": true
}

React Application

// tsconfig.json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "jsx": "ReactJSX",
    "jsxImportSource": "@emotion/react",
    "strict": true,
    "moduleResolution": "node"
  }
}

// Generated .swcrc
{
  "$schema": "https://swc.rs/schema.json",
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "jsx": true,
      "tsx": true
    },
    "target": "es2020",
    "transform": {
      "react": {
        "runtime": "automatic",
        "importSource": "@emotion/react"
      }
    }
  },
  "module": {
    "type": "es6"
  }
}

Library with Decorators

// tsconfig.json
{
  "compilerOptions": {
    "target": "ES2017",
    "module": "UMD",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "useDefineForClassFields": false,
    "declaration": true
  }
}

// Generated .swcrc
{
  "$schema": "https://swc.rs/schema.json",
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "target": "es2017",
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true,
      "useDefineForClassFields": false
    }
  },
  "module": {
    "type": "umd"
  }
}