gpt4 book ai didi

javascript - Webpack - 错误 : Cannot define 'query' and multiple loaders in loaders list

转载 作者:IT王子 更新时间:2023-10-29 03:05:02 24 4
gpt4 key购买 nike

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

我收到错误:无法在加载器列表中定义“查询”和多个加载器

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()
]
};

最佳答案

查询似乎是自定义单个 加载器行为的另一种方法,它比内联指定这些参数更清晰(见下文)。如果存在多个加载器,Webpack 不知道 query 配置适用于哪个。

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

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

编辑:虽然此解决方案适用于 Webpack 1,但请参阅其他答案以获得适用于更新版本的更清洁的解决方案。

关于javascript - Webpack - 错误 : Cannot define 'query' and multiple loaders in loaders list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35266706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com