Convert Figma logo to code with AI

swc-project logoswc

Rust-based platform for the Web

30,914
1,204
30,914
365

Top Related Projects

43,160

🐠 Babel is a compiler for writing next generation JavaScript.

37,921

An extremely fast bundler for the web

43,380

The zero configuration build tool for the web. 📦🚀

25,227

Next-generation ES module bundler

64,559

A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.

23,768

Unified developer tools for JavaScript, TypeScript, and the web

Quick Overview

SWC (Speedy Web Compiler) is a super-fast TypeScript/JavaScript compiler written in Rust. It aims to be a drop-in replacement for Babel, providing faster compilation times and improved performance. SWC can be used for both compilation and bundling of JavaScript and TypeScript projects.

Pros

  • Significantly faster compilation times compared to Babel
  • Written in Rust, offering better performance and memory safety
  • Supports modern JavaScript and TypeScript features
  • Can be used as a standalone tool or integrated into other build systems

Cons

  • Relatively newer project, may have fewer plugins and community resources compared to Babel
  • Some advanced or niche Babel features might not be fully supported
  • Learning curve for developers accustomed to Babel's ecosystem

Code Examples

  1. Basic JavaScript transformation:
const swc = require('@swc/core');

const code = `
const x = 1;
let y = 2;
`;

swc.transform(code, {
  jsc: {
    parser: {
      syntax: "ecmascript"
    },
    target: "es5"
  }
}).then(output => {
  console.log(output.code);
});
  1. TypeScript compilation:
const swc = require('@swc/core');

const code = `
interface Person {
  name: string;
  age: number;
}

const greet = (person: Person): string => {
  return `Hello, ${person.name}!`;
};
`;

swc.transform(code, {
  jsc: {
    parser: {
      syntax: "typescript"
    },
    target: "es2015"
  }
}).then(output => {
  console.log(output.code);
});
  1. Using SWC CLI for file compilation:
swc input.js -o output.js

Getting Started

To get started with SWC, follow these steps:

  1. Install SWC:
npm install --save-dev @swc/core @swc/cli
  1. Create a configuration file (.swcrc) in your project root:
{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2015"
  },
  "module": {
    "type": "commonjs"
  }
}
  1. Use SWC to compile your JavaScript files:
npx swc src -d dist

This will compile all JavaScript files in the src directory and output them to the dist directory.

Competitor Comparisons

43,160

🐠 Babel is a compiler for writing next generation JavaScript.

Pros of Babel

  • Mature ecosystem with extensive plugin support
  • Better documentation and community resources
  • Wider browser compatibility and more configurable

Cons of Babel

  • Slower compilation speed, especially for large projects
  • Higher memory usage during transpilation
  • More complex configuration required for optimal setup

Code Comparison

Babel configuration:

{
  "presets": ["@babel/preset-env"],
  "plugins": ["@babel/plugin-transform-runtime"]
}

SWC configuration:

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript"
    },
    "target": "es2015"
  }
}

Both Babel and SWC are JavaScript/TypeScript compilers and transpilers. Babel has been the industry standard for years, offering a rich ecosystem of plugins and presets. It provides excellent documentation and community support, making it easier for developers to solve complex transpilation issues.

SWC, on the other hand, is a newer, Rust-based compiler that focuses on speed and efficiency. It offers significantly faster compilation times and lower memory usage, making it particularly attractive for large-scale projects. However, SWC has a smaller ecosystem and less extensive documentation compared to Babel.

While Babel's configuration can be more complex, it offers greater flexibility and fine-tuned control over the transpilation process. SWC aims for simplicity in configuration, which can be beneficial for projects with straightforward requirements but may limit advanced customization options.

37,921

An extremely fast bundler for the web

Pros of esbuild

  • Extremely fast build times, often outperforming SWC in benchmarks
  • Simpler configuration and API, making it easier to set up and use
  • Smaller bundle size for the tool itself, which can be beneficial for CI/CD pipelines

Cons of esbuild

  • Less extensible compared to SWC, with fewer plugin options
  • More limited in terms of JavaScript/TypeScript transformation capabilities
  • Lacks some advanced features like decorator support (as of the latest stable version)

Code Comparison

SWC configuration example:

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "target": "es2015"
  }
}

esbuild configuration example:

require('esbuild').build({
  entryPoints: ['app.ts'],
  bundle: true,
  outfile: 'out.js',
  target: 'es2015'
})

Both tools aim to provide fast JavaScript/TypeScript compilation and bundling, but they have different strengths. SWC offers more advanced transformation capabilities and extensibility, while esbuild focuses on raw speed and simplicity. The choice between them depends on specific project requirements and performance needs.

43,380

The zero configuration build tool for the web. 📦🚀

Pros of Parcel

  • Zero configuration out of the box, making it easier for beginners
  • Supports a wide range of file types and assets without additional plugins
  • Faster build times due to multicore processing and caching

Cons of Parcel

  • Less flexible for complex configurations compared to SWC
  • May have larger bundle sizes for some projects
  • Limited ecosystem and plugin support compared to more established bundlers

Code Comparison

Parcel:

// No configuration needed, just run:
parcel index.html

SWC:

// Requires configuration:
const swc = require('@swc/core');
swc.transform(code, {
  jsc: {
    parser: {
      syntax: "ecmascript"
    },
    target: "es5"
  }
});

Summary

Parcel is ideal for quick setup and simple projects, offering a zero-config approach and broad asset support. SWC, on the other hand, provides more flexibility and potentially better performance for complex projects, but requires more configuration. Parcel's simplicity comes at the cost of customization, while SWC offers fine-grained control at the expense of initial ease of use.

25,227

Next-generation ES module bundler

Pros of Rollup

  • More mature and widely adopted in the JavaScript ecosystem
  • Excellent tree-shaking capabilities for smaller bundle sizes
  • Supports a wide range of plugins for extended functionality

Cons of Rollup

  • Slower build times compared to SWC's Rust-based implementation
  • Limited support for non-JavaScript assets without additional plugins
  • Less suitable for large-scale applications with complex configurations

Code Comparison

SWC (JavaScript transformation):

module.exports = {
  jsc: {
    parser: {
      syntax: "ecmascript",
      jsx: true,
    },
    transform: {
      react: {
        pragma: "React.createElement",
        pragmaFrag: "React.Fragment",
      },
    },
  },
};

Rollup (bundle configuration):

export default {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'iife'
  },
  plugins: [
    resolve(),
    commonjs()
  ]
};

SWC focuses on fast JavaScript/TypeScript transformation, while Rollup specializes in efficient module bundling with tree-shaking. SWC's configuration is centered around parsing and transforming code, whereas Rollup's configuration emphasizes input/output and plugin management for bundling.

64,559

A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.

Pros of webpack

  • Mature ecosystem with extensive plugin support and documentation
  • Handles a wide variety of asset types beyond JavaScript
  • Offers advanced code splitting and lazy loading capabilities

Cons of webpack

  • Slower build times, especially for large projects
  • Steeper learning curve and more complex configuration
  • Higher memory usage during builds

Code Comparison

webpack configuration:

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
};

SWC configuration:

module.exports = {
  entry: {
    web: './src/index.ts',
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
  },
};

Summary

webpack is a well-established bundler with a rich ecosystem and advanced features, making it suitable for complex projects with diverse asset types. However, it can be slower and more resource-intensive than SWC, especially for large codebases.

SWC, on the other hand, focuses on speed and simplicity, offering faster build times and a more straightforward configuration. It's particularly well-suited for JavaScript and TypeScript projects but may lack some of the advanced features and extensive plugin support found in webpack.

The choice between the two depends on project requirements, team expertise, and performance needs. webpack might be preferable for projects requiring extensive customization and asset handling, while SWC could be a better fit for teams prioritizing build speed and simplicity.

23,768

Unified developer tools for JavaScript, TypeScript, and the web

Pros of Rome

  • Aims to be an all-in-one toolchain, offering a more comprehensive solution
  • Focuses on developer experience with a unified configuration
  • Built with extensibility in mind, allowing for easier customization

Cons of Rome

  • Less mature and stable compared to SWC
  • Smaller community and ecosystem
  • Limited language support (primarily JavaScript and TypeScript)

Code Comparison

Rome:

import { readFile } from "rome";

const content = await readFile("example.js");
console.log(content);

SWC:

const swc = require("@swc/core");

const output = await swc.transform("code", {
  jsc: {
    parser: {
      syntax: "ecmascript"
    },
    target: "es5"
  }
});
console.log(output.code);

Summary

While Rome aims to provide a more comprehensive toolchain with a focus on developer experience, SWC offers a more mature and performant solution for specific tasks like transpilation and bundling. Rome's unified approach may appeal to developers looking for an all-in-one solution, while SWC's speed and stability make it a strong choice for projects requiring high-performance code transformation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

swc

Make the web (development) faster.

downloads (@swc/core) downloads (3rd party)

undefined GitHub release (latest SemVer)

GitHub code size in bytes node-current (scoped)

Discord

SWC (stands for Speedy Web Compiler) is a super-fast TypeScript / JavaScript compiler written in Rust. It's a library for Rust and JavaScript at the same time. If you are using SWC from Rust, see rustdoc and for most users, your entry point for using the library will be parser.

Also, SWC tries to ensure that

If you select the latest version of each crates, it will work

for rust users.

MSRV of crates is currently 1.73.

To update all SWC crates you use, you can run curl https://raw.githubusercontent.com/swc-project/swc/main/scripts/update-all-swc-crates.sh | bash -s. This script will update all dependencies to the latest version and run cargo build to ensure that everything works. Note that you need

  • jq
  • cargo upgrade

command to run the script.


If you are using SWC from JavaScript, please refer to docs on the website.

Documentation

Check out the documentation in the website.

Features

Please see comparison with babel.

Performance

Please see benchmark results on the website.

Supporting swc

Sponsors

SWC is a community-driven project, and is maintained by a group of volunteers. If you'd like to help support the future of the project, please consider:

Contributing

See CONTRIBUTING.md. You may also find the architecture documentation useful (ARCHITECTURE.md).

License

SWC is primarily distributed under the terms of the Apache License (Version 2.0).

See LICENSE for details.

NPM DownloadsLast 30 Days