在本教程之后,我在数组中添加了react-hot加载程序:https://thoughtbot.com/blog/setting-up-webpack-for-react-and-hot-module-replacement之后,出现了这个错误

我得了Error: Cannot define 'query' and multiple loaders in loaders list分.

var WebpackDevServer = require("webpack-dev-server");
var webpack = require('webpack');
var path = require('path');
require("babel-polyfill");

var BUILD_DIR = path.resolve(__dirname, 'build');
var APP_DIR = path.resolve(__dirname, 'src');

module.exports = {
  entry: [
    'babel-polyfill',
    'bootstrap-loader',
    'webpack/hot/dev-server',
    APP_DIR + '/import.js',
  ],
  output: {
    path: BUILD_DIR,
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      test: /\.jsx?$/,
      loaders: ['react-hot', 'babel'],
      exclude: /node_modules/,
      query: {
        plugins: ['transform-runtime'],
        presets: ['es2015', 'stage-0', 'react']
      }
    }, {
      test: /\.css$/,
      loader: "style-loader!css-loader"
    }, {
      test: /\.scss$/,
      loaders: ["style", "css", "sass"]
    }, {
      test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif)$/,
      loader: 'url-loader?limit=100000'
    }]
  },
  plugins: [
    new webpack.ProvidePlugin({
      $: "jquery",
      jQuery: "jquery"
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ]
};

推荐答案

查询似乎是定制single加载程序行为的另一种方式,比内联指定这些参数更简洁(见下文).如果存在多个加载程序,Webpack不知道query配置适用于哪个.

以下应该可以解决你的问题:

module: {
    loaders: [{
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loaders: ['react-hot', 'babel?presets[]=es2015,presets[]=stage-0,presets[]=react,plugins[]=transform-runtime']
    }

EDIT:当此解决方案适用于Webpack 1时,请参阅其他有关适用于更新版本的更清洁解决方案的答案.

Reactjs相关问答推荐

在触发onClick事件时,无法将焦点设置在material UI中的工具提示组件的内容上,但在触发onKeyPress事件时可以

来自Ldap.js的res.on(searchEntry)不会在Next.js生产模式下返回结果

过滤对象数组并通过迭代对象数组将属性放入新数组

为什么我的React App.js只在页面刷新时呈现3次?

如何使用TouchStart/TouchEnd在Table ReactJS中交换位置?

根据用户 Select 的注册类型更改表单字段

滚动视图样式高度没有任何区别

在 Next13 中将 props 传递给 onClick 从服务器到客户端组件

如何隐藏移动导航栏后面的向下滚动图标和文本?

Mui 在 TextField 标签上添加工具提示显示两个工具提示框

Next.js 和理智 | npm run build 时预渲染页面/时发生错误

i18next中复数键的理解

使用reactrouterdom时显示"对象无效作为React子组件"错误

我收到Uncaught TypeError: props.handleSelect is not a function

在 React 中,为什么在使用 addEventListener 时外部元素上的 onclick 事件监听器在内部元素的 onclick 事件监听器之前执行?

我应该使用 useEffect 来为 React Native Reanimated 的 prop 值变化设置动画吗?

更新 Next.js 路由查询更改的状态会导致无限循环

使用 React.UseEffect 从 api 获取但我的清理返回不起作用

如何制作基于对象 struct 呈现数据的可重用组件?

用 scss 覆盖 MUI