Socket
Socket
Sign inDemoInstall

babel-plugin-preact-require

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-preact-require

Babel plugin that adds Preact import declaration if file contains JSX tags.


Version published
Maintainers
1
Install size
9.14 kB
Created

Readme

Source

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"
  ]
}

Keywords

FAQs

Last updated on 04 Mar 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc