GithubHelp home page GithubHelp logo

import-jsx's Introduction

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.js

const React = require('react');

module.exports = <div/>;

preact.js

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

module.exports = <div/>;

custom.js

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

Enable or disable caching of transpiled sources.

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

License

MIT © Vadim Demedes

import-jsx's People

Contributors

isaacs avatar sindresorhus avatar

Watchers

James Cloos avatar

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.