首页 > node.js > ReactJS的环境设置

ReactJS的环境设置 (environment setup for ReactJS)

问题

目前我正在使用npm(babel,webpack等)为react.js做环境设置,现在我正在填写webpack.config.js文件和我正在关注的教程有下一个代码:

 module: {
  rules: [
     {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
           presets: ['es2015', 'react']
        }
     }
  ]
},

正如我在礼物属性中所看到的那样写了es2015(ECMAScript 5),我想知道它更好是那样,或者我应该将它切换到ES6或ES7,因为它是2019年甚至ES6有更多的功能。我刚开始做出反应,如果我问了一些愚蠢的话,请指正。谢谢

解决方法

你需要@babel/preset-env包而不是es2015

问题

currently i am doing environment setup for react.js with npm (babel, webpack and etc.) and i now i am filling webpack.config.js file and tutorial that i am following has next code :

 module: {
  rules: [
     {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
           presets: ['es2015', 'react']
        }
     }
  ]
},

and as i see in presents property there are written es2015 (ECMAScript 5) and i want to know it is better be like that or i should switch it to ES6 or ES7 because it is 2019 and even ES6 has way too more features. i just started react and if i asked something stupid, correct me. thanks

解决方法

you need @babel/preset-env package instead of es2015

相似信息