Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-jsx-to-htm

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-jsx-to-htm

Babel plugin to compile JSX to Tagged Templates.

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
decreased by-87.79%
Maintainers
2
Weekly downloads
 
Created
Source

babel-plugin-transform-jsx-to-htm

This plugin converts JSX into Tagged Templates that work with htm.

// INPUT:
const Foo = () => <h1>Hello</h1>

// OUTPUT:
const Foo = () => html`<h1>Hello</h1>`

Installation

Grab it from npm:

npm i -D babel-plugin-transform-jsx-to-htm

... then add it to your Babel config (eg: .babelrc):

"plugins": [
  "babel-plugin-transform-jsx-to-htm"
]

Options

The following options are available:

OptionTypeDefaultDescription
tagString"html"The "tag" function to prefix [Tagged Templates] with.
importfalse|String|ObjectfalseAuto-import a tag function, off by default.
See Auto-importing a tag function for an example.

Options are passed to a Babel plugin using a nested Array:

"plugins": [
  ["babel-plugin-transform-jsx-to-htm", {
    "tag": "$$html"
  }]
]

Auto-importing the tag

Want to automatically import html into any file that uses JSX? Just use the import option:

"plugins": [
  ["babel-plugin-transform-jsx-to-htm", {
    "tag": "$$html",
    "import": {
      // the module to import:
      "module": "htm/preact",
      // a named export to use from that module:
      "export": "html"
    }
  }]
]

The above will produce files that look like:

import { html as $$html } from 'htm/preact';

export default $$html`<h1>hello</h1>`

License

Apache 2

Keywords

FAQs

Package last updated on 09 Jul 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc