Babel Plugin for Vue Functional JSX

2.1.0 · active · verified Sun Apr 19

babel-plugin-jsx-vue-functional is a Babel plugin designed to simplify the creation of Vue.js functional components using JSX syntax. It automatically transforms arrow functions containing JSX into Vue functional component definitions, making it easier to write lightweight, render-only components. The current stable version is 2.1.0. This plugin primarily acts as syntactic sugar, working in conjunction with `@vue/babel-plugin-jsx` (or `transform-vue-jsx`) to enable a more concise way of declaring functional components within a Vue JSX setup. It differentiates itself by explicitly handling the transformation of named arrow functions into `functional: true` component objects, which is particularly useful for performance optimizations and simpler component structures in Vue applications. While its release cadence isn't frequent, updates typically address compatibility or add developer tooling enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure babel-plugin-jsx-vue-functional in your Babel setup and write a simple Vue functional component using the enhanced JSX syntax provided by the plugin.

{
  // .babelrc or babel.config.js
  "presets": [
    ["@babel/preset-env", { "targets": { "node": "current" } }]
  ],
  "plugins": [
    "jsx-vue-functional",
    "@vue/babel-plugin-jsx"
  ]
}

// src/components/MyFunctionalComponent.js
// Example of a functional component using JSX syntactic sugar
const GreetUser = ({ props }) => <h1>Hello, {props.name}!</h1>

export const MyComponent = ({ props, listeners }) => (
  <div onClick={listeners.click}>
    <GreetUser name={props.userName} />
    <p>This is a functional component example.</p>
  </div>
)

// This will be transpiled into:
// const GreetUser = {
//   functional: true,
//   render: (h, { props }) => <h1>Hello, {props.name}!</h1>
// }
// export const MyComponent = {
//   functional: true,
//   render: (h, { props, listeners }) => (
//     <div onClick={listeners.click}>
//       <GreetUser name={props.userName} />
//       <p>This is a functional component example.</p>
//     </div>
//   )
// }

view raw JSON →