Package Exports
- babel-plugin-react-require
- babel-plugin-react-require/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-react-require) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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-requireinto.babelrc. This plugin should be defined beforetransform-es2015-modules-commonjsplugin because it's using ES2015 modules syntax to importReactinto scope.
{
"plugins": [
"react-require"
]
}