0.1.0 • Published 1 year ago

swc-plugin-import-jsx-pragma v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

swc-plugin-import-jsx-pragma

SWC plugin for automatically injecting an import statement for JSX pragma in classic runtime.

Installation

npm i -D swc-plugin-import-jsx-pragma

Usage

See jsc.experimental.plugins:

// .swcrc
{
  "jsc": {
    "transform": {
      "react": {
        // Currently, these are the required configs.
        "runtime": "classic",
        "pragma": "createElement",
        "pragmaFrag": "Fragment",
      },
    },
    "experimental": {
      "plugins": [
        ["swc-plugin-import-jsx-pragma", {}]
      ]
    }
  }
}

It will take this input:

export default function App() {
  return <h1>Hello World</h1>
}

And generate this output:

import { createElement } from "react";
export default function App() {
    return /*#__PURE__*/ createElement("h1", null, "Hello World");
}

Options

  • importSource: string, defaults to react.
0.1.0

1 year ago