SkillByAIइंटरैक्टिव संस्करण खोलें →

पाठ 22 / 31

SWC Configuration और Options

SWC को .swcrc targets, parser settings और module options से configure करें और automatic JSX runtime उपयोग करें।

.swcrc .babelrc से simpler है

SWC का config अधिक opinionated है: कम options, स्पष्ट structure। आप targets निर्दिष्ट करते हैं, enable/disable करने के लिए features, और वह ज्यादातर है।

पूर्ण .swcrc उदाहरण

एक typical SWC config में env (targets), jsc (parser/syntax), और module settings शामिल हैं।

{
  "env": {
    "targets": { "chrome": "90", "firefox": "88" }
  },
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "transform": {
      "react": { "runtime": "automatic" }
    }
  },
  "module": {
    "type": "es6"
  }
}

SWC का JSX डिफ़ॉल्ट रूप से automatic है

SWC डिफ़ॉल्ट रूप से React 17+ automatic JSX का उपयोग करता है (React import की जरूरत नहीं)। Babel की classic setup से कम boilerplate।