作者:cuishy | 来源:互联网 | 2023-01-31 18:47
我的webpack.config.js
var path = require("path")
var webpack = require('webpack')
var BundleTracker = require('webpack-bundle-tracker')
module.exports = {
context: __dirname,
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./assets/js/index', // entry point of our app. assets/js/index.js should require other js modules and dependencies it needs
],
output: {
path: path.resolve('./assets/bundles/'),
filename: "[name]-[hash].js",
publicPath: 'http://localhost:3000/assets/bundles/', // Tell django to use this URL to load packages and not use STATIC_URL + bundle_name
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(), // don't reload if there is an error
new BundleTracker({filename: './webpack-stats.json'}),
],
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: ['react-hot-loader', 'babel-loader?presets[]=react'],
}, // to transform JSX into JS
],
},
resolve: {
modules: ['node_modules', 'bower_components'],
extensions: ['.js', '.jsx']
},
}
错误:
错误:模块'C:\ Workspace\PyCharmProjects\ProjectPearl \node_modules\react-hot-loader\index.js'不是加载程序(必须具有正常或俯仰功能)
通过为模块添加-loader扩展看起来有些工作(https://github.com/webpack/webpack/issues/3180),但对我来说它仍然无法解决.
请协助.
1> Mukesh Soni..:
我认为用法是 react-hot-loader/webpack
loaders: ['react-hot-loader/webpack', 'babel-loader?presets[]=react'],
在这里查看一些示例用法http://gaearon.github.io/react-hot-loader/getstarted/
如果人们使用ES6并得到相同的错误,请注意[迁移指南](https://github.com/gaearon/react-hot-loader/tree/master/docs#migration-to-30)读取作为第一步:如果你正在使用Babel和ES6,**从你的Webpack配置中的任何加载器中删除react-hot loader,并将react-hot-loader/babel添加到.babelrc的插件部分: