ij

import-jsx

Require and transpile JSX on the fly

Showing:

Popularity

Downloads/wk

62.9K

GitHub Stars

137

Maintenance

Last Commit

1yr ago

Contributors

5

Package

Dependencies

9

Size (min+gzip)

256.0KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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');

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100