@vue/babel-sugar-functional-vue

Babel syntactic sugar for functional components
36,561,033 1,474
Install
npm install @vue/babel-sugar-functional-vue
Latest Version:1.4.0
Vue:2
License:MIT
Last Updated:May 31, 2024
Links: GitHub  ·  npm
Maintainer: nickmessing

@vue/babel-sugar-functional-vue

Syntactic sugar for functional components.

Babel Compatibility Notes

Usage

Install the dependencies:

# for yarn:
yarn add @vue/babel-sugar-functional-vue
# for npm:
npm install @vue/babel-sugar-functional-vue --save

In your .babelrc:

{
  "plugins": ["@vue/babel-sugar-functional-vue"]
}

However it is recommended to use the configurable preset instead.

Details

This plugin transpiles arrow functions that return JSX into functional components but only if it's an uppercase variable declaration or default export:

// Original:
export const A = ({ props, listeners }) => <div onClick={listeners.click}>{props.msg}</div>
export const b = ({ props, listeners }) => <div onClick={listeners.click}>{props.msg}</div>
export default ({ props, listeners }) => <div onClick={listeners.click}>{props.msg}</div>

// Result:
export const A = {
  functional: true,
  render: (h, {
    props,
    listeners
  }) => <div onClick={listeners.click}>{props.msg}</div>
}
export const b = ({ props, listeners }) => <div onClick={listeners.click}>{props.msg}</div>
export default {
  functional: true,
  render: (h, {
    props,
    listeners
  }) => <div onClick={listeners.click}>{props.msg}</div>
}

Related Packages

@vue/devtools-api

Plugins API for easier DevTools integrations.

471,046,026 2,932
@vue/compiler-vue2

template compiler for Vue 2.x

184,385,144 212,629
@vue/test-utils

Component testing utils for Vue 3.

171,749,877 1,161
@vue/babel-plugin-jsx

Babel plugin for Vue 3 JSX

153,148,630 1,781
@vue/eslint-config-typescript

ESLint config for TypeScript + Vue.js projects

76,955,056 192

Version History

Version Released Vue License
1.4.0 ^2.5.17 MIT
1.2.2 ^2.5.17 MIT
1.2.1 ^2.5.17 MIT
1.2.0 ^2.5.17 MIT
1.1.2 ^2.5.17 MIT
Pre-releases (3)
Version Released Vue License
1.0.0-beta.3 ^2.5.17 MIT
1.0.0-beta.2 ^2.5.17 MIT
1.0.0-beta.1 ^2.5.17 MIT