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

import-jsx

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

import-jsx

Require and transpile JSX on the fly

  • 4.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
42K
decreased by-13.65%
Maintainers
1
Weekly downloads
 
Created
Source

import-jsx Build Status

Require and transpile JSX on the fly

  • Doesn't install any require() hooks
  • Auto-detects React pragma (React.createElement) and falls back to h pragma supported by Preact and others
  • Caches transpiled sources by default
  • Bundles in object rest spread transform

Install

$ npm install --save import-jsx

Usage

const importJsx = require('import-jsx');

const reactComponent = importJsx('./react');
const preactComponent = importJsx('./preact');
const customComponent = importJsx('./custom', {pragma: 'x'});

React

const React = require('react');

module.exports = <div />;

Preact

const {h} = require('preact');

module.exports = <div />;

Any JSX pragma

const x = (tagName, attrs, ...children) => {};

module.exports = <div />;

API

importJsx(moduleId, [options])

moduleId

Type: string

Module id.

options
pragma

Type: string
Default: h

Override JSX pragma.

pragmaFrag

Type: string
Default: Fragment

Override pragma for JSX fragments.

cache

Type: boolean
Default: true

Cache transpiled source code.

importJsx.create([options])

Factory method to create a version of importJsx() with pre-defined options. Useful when you need a custom pragma, but don't want to pass it along with each importJsx() call.

options

Type: object

Options to pass to importJsx().

// Before
const importJsx = require('import-jsx');

importJsx('./a', {pragma: 'x'});
importJsx('./b', {pragma: 'x'});

// After
const importJsx = require('import-jsx').create({pragma: 'x'});

importJsx('./a');
importJsx('./b');

Keywords

FAQs

Package last updated on 05 Jan 2022

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