10 releases

0.4.0 Mar 13, 2025
0.3.2 Jul 18, 2024
0.3.1 Jun 2, 2024
0.3.0 Feb 1, 2024
0.2.1 Mar 23, 2023

#2 in #vue

Download history 2/week @ 2024-12-04 12/week @ 2024-12-11 1/week @ 2025-02-19 131/week @ 2025-03-12

132 downloads per month

MIT license

150KB
3.5K SLoC

SWC Plugin for Vue JSX

SWC plugin for transforming Vue JSX, mostly ported from official Babel plugin. It only supports Vue.js v3 or newer.

Installation

npm i -D swc-plugin-vue-jsx

Configuration

You can configure your .swcrc file.

Minimum Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": true
    },
    "experimental": {
      "plugins": [["swc-plugin-vue-jsx", {}]]
    }
  }
}

Options

These options of official Babel plugin are supported:

  • transformOn
  • optimize
  • mergeProps
  • enableObjectSlots
  • pragma
  • resolveType (Types imported from other modules aren't supported.)

For details, please refer to official documentation.

The isCustomElement can't be supported directly, because SWC config only allows JSON, so we introduce the customElementPatterns option instead.

It accepts an array of strings which represent regex.

For example:

[
  "swc-plugin-vue-jsx",
  {
    "customElementPatterns": ["^i-"]
  }
]

All HTML tags which match the pattern ^i- will be treated as custom elements.

Advanced Config Example

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": true
    },
    "experimental": {
      "plugins": [
        [
          "swc-plugin-vue-jsx",
          {
            "transformOn": true,
            "optimize": true
          }
        ]
      ]
    }
  }
}

License

MIT License

Copyright (c) 2022-present Pig Fang

Dependencies

~5–7.5MB
~125K SLoC