GithubHelp home page GithubHelp logo

impronunciable / babel-plugin-preact-require Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vslinko/babel-plugin-react-require

7.0 2.0 0.0 21 KB

[TODO] Babel plugin that adds React import declaration if file contains JSX tags

License: MIT License

JavaScript 100.00%
preact babel jsx

babel-plugin-preact-require's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.