我的一个组件中有一个外部 css 导入 -
import "rc-slider/assets/index.css";
但是,在使用 webpack 构建时,未注册 css。我已经尝试@import '~rc-slider/assets/index.css';在我的组件 module.css 文件中添加一个以波浪号为前缀的导入,但这不起作用。我还尝试添加include: [path.join(__dirname, '..', 'node_modules')],到我的 webpack.config.js 文件中,它导致构建失败,并显示我的每个文件的多个错误You may need an appropriate loader to handle this file type.。
我的 webpack.config.js 文件如下:
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
const HtmlWebPackPlugin = require("html-webpack-plugin");
const autoprefixer = require("autoprefixer");
const path = require("path");
module.exports = {
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.html$/,
use: [
{
loader: "html-loader"
}
]
},
{
test: /\.(scss|css)$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader",
options: {
importLoaders: 2,
modules: true,
localIdentName: "[name]__[local]__[hash:base64:5]"
}
},
{
loader: "sass-loader"
},
{
loader: "postcss-loader",
options: {
ident: "postcss",
plugins() {
return [autoprefixer];
}
}
},
]
},
{
test: /\.(png|jp(e*)g|gif|svg)$/,
use: [
{
loader: "url-loader",
options: {
limit: 8000,
name: "images/[hash]-[name].[ext]"
}
}
]
}
]
},
plugins: [
new HtmlWebPackPlugin({
template: "./src/index.html"
}),
new BundleAnalyzerPlugin()
]
};
这已经占用了我半天的时间,所以任何输入都会有很大的帮助。谢谢你。