Stand-alone functional components and reaction import

I ran into the same issue as here https://github.com/babel/babel/issues/2504

Thus, any file that has only stateless components should have react, imported as import React from 'react';, which is a little annoying (eslint gives an error as an unused variable, which, as I understand it, can be suppressed, is still ...). Is there any way to avoid this import in customization webpack.

thanks.

+4
source share
2 answers

I had the same problem. Then I found this:

babel-plugin-react-require

require import, 'react', .

P.S. webpack babel6, , jsx-loader JSX. , , jsx-loader . :

babel-preset-

+2

Webpack ProvidePlugin (https://github.com/webpack/docs/wiki/shimming-modules#plugin-provideplugin):

new webpack.ProvidePlugin({
    React: "react"
})

React import React from 'react'

0

Source: https://habr.com/ru/post/1613708/


All Articles