Communitygithub.com

G1Joshi/Agent-Skills

高性能なRustベースのJavaScript/TypeScriptコンパイル、.swcrc設定、@swc/jestによるJestテスト、ミニファイケーションをカバーするSWCエキスパート支援。BabelをSWCに置き換えてビルドを高速化したり、テスト実行を加速したり、最新のECMAScript機能をコンパイルする場合に使用します。

Agent-Skills とは?

このスキルは、Rustベースの高速WebコンパイラであるSWC(Speedy Web Compiler)に関する専門的な支援を提供します。Next.jsやDenoの内部コンパイラとしても使われており、Babelの代替として最大20倍の高速トランスパイルを実現します。TypeScript/JSXのコンパイル、@swc/jestによるJestテスト高速化、.swcrc設定ファイルの最適化、プロダクション用のJS/CSSミニファイケーションなどをカバーします。特に、BabelからSWCへの移行を検討している開発者や、Next.jsやWebpack/Turbopackパイプラインでのビルドパフォーマンス向上を目指すチームにとって有用です。最後に、トラブルシューティングテーブルやベストプラクティス(2026年版)も含まれており、SWCの導入から運用までを包括的にサポートします。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/G1Joshi/Agent-Skills/tree/HEAD/skills/tools/swc

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

SWC

SWC (Speedy Web Compiler) はRustベースの拡張可能なプラットフォームです。Next.js と Deno の内部コンパイラとして使用されています。

使用すべきタイミング

  • 高性能なJavaScript/TypeScriptトランスパイル: BabelをRustベースのコンパイラに置き換え、最大20倍の高速化を実現。
  • Next.js および最新バンドラーパイプライン: React JSX、TSX、最新のECMAScript機能、Webpack/Turbopackアセットのトランスパイル。
  • プログラムによるAST操作とコード生成: @swc/core Node.js APIを使用した高速カスタムビルドツールの構築。
  • プロダクションアセットのミニファイ: @swc/core ミニファイアを使用したJSおよびCSSバンドルの超高速ミニファイ。

クイックスタート

1. 最小限の .swcrc

{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": true
    },
    "transform": {
      "react": {
        "runtime": "automatic"
      }
    },
    "target": "es2022"
  },
  "minify": false
}

2. CLIでコンパイル

npx @swc/cli src -d dist

コアコンセプト

プロダクション用SWC設定(.swcrc)

最新のTypeScript、React 19 JSXランタイム、モジュールトランスパイルを設定:

{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": true,
      "dynamicImport": true
    },
    "transform": {
      "react": {
        "runtime": "automatic",
        "refresh": true
      }
    },
    "target": "es2022",
    "loose": false,
    "externalHelpers": true,
    "keepClassNames": true,
    "minify": {
      "compress": {
        "unused": true,
        "drop_console": true
      },
      "mangle": true
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": true,
  "sourceMaps": true
}

@swc/core APIによるプログラム的コンパイル

Node.jsスクリプト内でソースファイルを非同期トランスパイル:

import swc from "@swc/core";
import fs from "node:fs/promises";

async function compileTypeScript(filePath) {
  const code = await fs.readFile(filePath, "utf-8");

  const output = await swc.transform(code, {
    filename: filePath,
    sourceMaps: true,
    jsc": {
      parser: { syntax: "typescript", tsx: true },
      target: "es2022",
    },
    module: { type: "commonjs" },
  });

  console.log("トランスパイルされたコード:\n", output.code);
  if (output.map) {
    console.log("ソースマップが生成されました");
  }
}

compileTypeScript("./src/index.ts");

高速CLIトランスパイル

SWCコマンドラインで直接ディレクトリツリーをコンパイル:

# ソースマップ付きでsrc/からdist/へトランスパイル
npx swc src -d dist --copy-files --source-maps

# swcpackでトランスパイルしてバンドル
npx swc src/index.ts -o dist/bundle.js --minify

一般的なパターン

@swc/jestでJestテストを高速化

問題: ts-jest を使用したTypeScriptトランスパイルによりテストスイートの実行が非常に遅くなる。
解決策: ts-jest を @swc/jest に置き換える。

// jest.config.js
module.exports = {
  transform: {
    "^.+\\.(t|j)sx?$": [
      "@swc/jest",
      {
        jsc: {
          transform: {
            react: { runtime: "automatic" },
          },
        },
      },
    ],
  },
};

SWCバンドリング&ミニファイパイプライン

問題: プロダクションビルドスクリプトの高速なミニファイが必要。
解決策: .swcrc 内で minify オプションを有効にする。

{
  "minify": true,
  "jsc": {
    "minify": {
      "compress": {
        "drop_console": true
      },
      "mangle": true
    }
  }
}

ベストプラクティス(2026年)

  • 推奨: @swc/helpers をインストールし externalHelpers: true を有効にして、トランスパイルランナーのヘルパースタブが重複するのを回避する。
  • 推奨: CI/CDパイプラインでSWCと tsc --noEmit を組み合わせる(SWCは型チェックを行わずにコードをトランスパイルするため)。
  • 推奨: ネイティブの最新ブラウザ機能を活用するため、target: "es2022" 以降を設定する。
  • 推奨: @swc/jest または @swc/register を使用して単体テストの実行を大幅に高速化する。
  • 非推奨: やむを得ない場合を除きBabelプラグインに依存しない。ネイティブのSWCプラグイン(Wasmプラグイン)が存在するか確認する。
  • 非推奨: .swc ビルドキャッシュディレクトリをGitリポジトリにコミットしない。
  • 非推奨: プロダクションのトラブルシューティングのためにソースマップを生成せずにSWCミニファイを実行しない。

トラブルシューティング

エラー / 症状原因解決策
failed to handle: error parsing typescript.swcrc でフラグを有効にせずにTypeScript構文(JSXやデコレーターなど)を使用しているjsc.parser に "syntax": "typescript"、"tsx": true、"decorators": true が含まれていることを確認。
デコレーターのメタデータが出力されない(Reflect.getMetadata が undefined を返す)transform.legacyDecorator と transform.decoratorMetadata が設定されていないjsc.transform 内で "legacyDecorator": true と "decoratorMetadata": true を設定。
Cannot find module '@swc/core-darwin-arm64'npm/yarnインストール中にネイティブバイナリのインストールに失敗したnpm install --force @swc/core を実行して対象アーキテクチャのネイティブバイナリを再フェッチ。

参考リンク

Individual skills in this repo

This repo contains 11 individual skills — each has its own dedicated page.

G1Joshi/Agent-Skills

Expert Dask distributed computing assistance covering Dask DataFrames, Arrays, Futures, and cluster scaling. Use when analyzing datasets too large for pandas on a single machine or multi-node cluster.

G1Joshi/Agent-Skills

Expert dbt (data build tool) assistance covering SQL modeling, Jinja macros, tests, documentation, and semantic layer. Use when building analytics engineering pipelines on BigQuery, Snowflake, or PostgreSQL.

G1Joshi/Agent-Skills

Expert JAX assistance covering Autograd, XLA compilation (`jit`), vectorization (`vmap`), and parallelization (`pmap`). Use when building high-performance numerical computing and cutting-edge deep learning research.

G1Joshi/Agent-Skills

Expert Ray distributed computing assistance covering Ray Core (actors, tasks), Ray Train, Ray Tune, and Ray Serve. Use when scaling Python compute and ML training across multi-node clusters.

G1Joshi/Agent-Skills

Expert Git version control assistance covering branching, interactive rebase, cherry-pick, submodules, worktrees, and conflict resolution. Use when managing source code history and collaboration workflows.

G1Joshi/Agent-Skills

Expert K9s CLI assistance covering terminal Kubernetes cluster navigation, real-time log streaming, port forwarding, and pod debugging. Use when managing and troubleshooting Kubernetes clusters with speed.

G1Joshi/Agent-Skills

Expert Tig assistance covering text-mode interface for Git, interactive staging, commit graph visualization, diff exploration, and blame navigation. Use when navigating Git commit history in the terminal, staging hunks interactively, browsing file changes, or reviewing revisions.

G1Joshi/Agent-Skills

Expert Vim assistance covering modal editing, .vimrc configuration, registers, macros, search/replace, and plugin management via vim-plug. Use when editing text efficiently in terminal environments, writing Vimscript, recording macros, or configuring core Vim settings.

G1Joshi/Agent-Skills

Expert Zed editor assistance covering high-performance Rust-based text editing, multi-buffer editing, language server protocols (LSP), and AI assistant integrations. Use when configuring Zed settings.json, setting up language extensions, collaborating in real-time channels, or optimizing editor startup speed.

G1Joshi/Agent-Skills

Expert Zsh assistance covering shell customization, Oh My Zsh plugins, Zinit plugin manager, prompt engineering (Starship/Powerlevel10k), and shell scripting. Use when configuring .zshrc, writing Zsh automation scripts, optimizing shell startup time, or configuring tab-completion.

G1Joshi/Agent-Skills

Expert [skill-name] assistance covering [feature 1], [feature 2], and [feature 3]. Use when [working with X], [debugging Y], or [implementing Z].

関連スキル