我是 Webpack 和 React 的真正初学者。我想使用一些 npm (carousel multi react),但我不能。我的 webpack.config 有问题。不幸的是,我自己无法解决这个问题,我看到了一些类似的主题,但它对我不起作用……或者我只是不知道如何在我的文件中实施解决方案。
./node_modules/react-multi-carousel/lib/styles.css 中的错误 1:0 模块解析失败:意外字符 ‘@’ (1:0) 您可能需要适当的加载器来处理此文件类型,目前没有加载器配置为处理此文件。见 https://webpack.js.org/concepts#loaders
const path = require("path");
const Html = require('html-webpack-plugin');
module.exports = {
entry: [
"whatwg-fetch",
"./js/index.js",
],
output: {
filename: "js/out.js",
path: path.resolve(__dirname, "build")
},
devServer: {
port: 3001,
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
}
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
{
loader: "postcss-loader",
options: {
plugins: () => [
require("autoprefixer")()
],
},
},
'sass-loader',
]
},
{
test: /\.(jpg|jpeg|gif|png)$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
publicPath: 'images',
outputPath: 'images',
}
}
},
{
test: /\.(eot|ttf|woff|woff2)$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
publicPath: 'fonts',
outputPath: 'fonts',
}
}
},
]
},
plugins: [
new Html({
filename: 'index.html',
template: './index.html',
})
]
};
原文由 Paul 发布,翻译遵循 CC BY-SA 4.0 许可协议
尝试将以下 json 添加到规则数组中。
还要为上述加载程序安装所需的 npm 模块,否则您也可以尝试将
test: /\.(sass|css)$/,
添加到当前设置中。