How to get ReactJs to integrate with Webpack?

前端 未结 1 1634
情书的邮戳
情书的邮戳 2020-12-22 13:11

Basically, I have just been through this simple tutorial, and now I want to get it to use React so I can see that display.

When I had this code:

mod         


        
相关标签:
1条回答
  • 2020-12-22 13:31

    Yeap, you are right you need babel-loader for your JSX code. Also if you use ES6 syntax with React you also need babel-core & babel-preset-es2015 & babel-preset-react npm's modules. After that incude all of them into your webpack.config.js file as below:

    module.exports = {
      //.. some stuff before
      module: {
        loaders: [{
          test: /\.js$/,
          exclude: /node_modules/,
          loaders: ["babel"],
          query: { presets: ['es2015','react'] }
        }]
      }
      //.. another stuff
    
    }
    

    Also i leave a link for you, with tutorial how to use ise.

    I hope it will help you.

    Thanks

    0 讨论(0)
提交回复
热议问题