webpack配置react-hot-loader出现错误

ERROR in ./entry.js
Module build failed: Error: React Hot Loader: The Webpack loader is now exported separately. If you use Babel, we recommend that you remove "react-hot-loader" from the "loaders" section of your Webpack configuration altogether, and instead add "react-hot-loader/babel" to the "plugins" section of your .babelrc file. If you prefer not to use Babel, replace "react-hot-loader" or "react-hot" with "react-hot-loader/webpack" in the "loaders" section of your Webpack configuration.

这个是为什么。

webpack.config.js

module.exports = {
entry:'./entry.js',
output:{

path:__dirname,
filename:'bundle.js'

},
devtool:'source-map',
module:{

loaders:[
  {test:[/\.js$/,/\.jsx?$/],exclude:/(node_modules)/,loader:'react-hot!babel'},
  {test:/\.css$/,loader:'style!css'}
]

}
};

阅读 5.6k
4 个回答

react-hot!babel 是 react-hot=loader v1 的用法。v1 的热加载存在不少问题,现在已经发布 react-hot-loader v3,推荐使用。如果对 react-hot-loader 版本问题有疑问可参考 react 热加载方案

loader这么写吧

loaders: ['react-hot', 'babel?presets[]=react,presets[]=es2015']`
新手上路,请多包涵
新手上路,请多包涵

.babelrc

{
"presets": [

"es2015",
"react",
"stage-0"

],
"plugins": [

"react-hot-loader/babel"

]
}

webpack.[dev.]config.js

entry: [
    'react-hot-loader/patch',
    path.join(__dirname, 'src/index.js')
]


https://github.com/brickspert...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题