babel-plugin-preact-require
v1.0.0
Published
Babel plugin that adds Preact import declaration if file contains JSX tags.
Downloads
349
Maintainers
Readme
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 beforetransform-es2015-modules-commonjs
plugin because it's using ES2015 modules syntax to import preact'sh
into scope.
{
"plugins": [
"preact-require"
]
}