babel-plugin-preact-require

1.0.0 • Public • Published

babel-plugin-preact-require

Babel plugin that adds Preact's h declaration if file contains JSX tags.

This plugin is only about stateless components that doesn't extends Component. If you want to use any other Preact functions then you should import their by yourself.

This code was forked from babel-plugin-react-require so all credit should go to @vslinko

Example

Your component.js that contains this code:

export default function Component() {
  return (
    <div />
  )
}

will be transpiled into something like this:

import { h } from 'preact'
 
export default function Component() {
  /* this part will be transpiled by babel itself as usual */
  return (
    h('div')
  )
}

Usage

  • Install babel-plugin-preact-require.
npm install babel-plugin-preact-require --save-dev
  • Add preact-require into .babelrc. This plugin should be defined before transform-es2015-modules-commonjs plugin because it's using ES2015 modules syntax to import preact's h into scope.
{
  "plugins": [
    "preact-require"
  ]
}

Package Sidebar

Install

npm i babel-plugin-preact-require

Weekly Downloads

65

Version

1.0.0

License

MIT

Last publish

Collaborators

  • danzajdband