4.0.2 • Published 6 months ago

babel-plugin-react-require v4.0.2

Weekly downloads
98,727
License
MIT
Repository
github
Last release
6 months ago

babel-plugin-react-require

Babel plugin that adds React import declaration if file contains JSX tags.

This plugin is only about stateless components that doesn't extends React.Component. If you want to use any other React functions then you should import their by yourself.

Example

Your component.js that contains this code:

export default function Component() {
  return (
    <div />
  );
}

will be transpiled into something like this:

import React from 'react';

export default function Component() {
  /* this part will be transpiled by babel itself as usual */
  return (
    React.createElement('div')
  );
}

Usage

  • Install babel-plugin-react-require.
npm install babel-plugin-react-require --save-dev
  • Add react-require into .babelrc. This plugin should be defined before transform-es2015-modules-commonjs plugin because it's using ES2015 modules syntax to import React into scope.
{
  "plugins": [
    "react-require"
  ]
}
@react-ssr/coresupermario-clisuper-mario-clikelex-clikelex-plugin-appcmtter-lib2conquista-componentesares-nextyesroad-npm-storybook@c11/engine.cli-service-webtest-brandi-ysw@cloudkite/nextfather-build-mbptest@service-exchange/buildtoast-react-non-blocking-notifications@infinitebrahmanuniverse/nolb-babel-plugin-rbabel-preset-common@everything-registry/sub-chunk-1203@explodingcamera/nextbabel-preset-umi-sudoku356-testdepot-babel-presetdepot-librarysheerun-nextsen-testdreactsilkiscot4dtd-clidxc-webpackera-build-utilsstatic-next@dhis2/cli-app-scriptsredbudredocgenrowl-clirun-pipelinerugalrpm-common2roadhogroadhog-croadhog-extraroadhog-ezzroadhog2roadhogxreskriptreta-clireact-scripts-prosoda-react-scripts@darktower/zero-common-deps@de-mklinger/chargedihogdn-middleware-babel@axew/jugg-plugin-react@bcoe/nextcathay-roadhog@cachelayer/react-scriptscmtter-libcmtter-lib4porschewodax-umi-fatherwodax-umi-librarywodax-babel-preset-umilibrary-utillynn-roadhogcook-father-buildprevjscontoh-ganteng@cross2d/next@birman/babel-preset-birman@c11/engine.service-web@blorajs/babel-preset-umi@bayuganteng11/contoh-gantengcraco-flying-saucer@bridge5/preset-env-react@brendonjohn/react-ssr-core@brendonjohn/react-ssr-static@antchain/father-build@yeatszhang/babel-preset1fl@assits/bro-buildblockstack-react-scriptsnxm-core@arnosaine/cra-template-helpersomi-rollqysmhogrc-ts-scriptsrc-ts-tools@dawnjs/babel-preset-dawn@ailjc/buildbcs-toolsbfe-cli@anansi/babel-preset@aliangincoding/react-scriptsaviateavet-buildavocode-next@xxx-ssr/corenpm-all-packagesflareactsun-build
4.0.1

9 months ago

4.0.2

6 months ago

4.0.0

11 months ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.2

5 years ago

3.0.1

6 years ago

3.0.0

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.0.2

9 years ago

1.0.1

9 years ago