首页 > 解决方案 > 无法从节点模块包加载 css

问题描述

我正在尝试从节点模块包中导入 css。

import "packageName/dist/index.bundle.css";

我收到错误消息“当前没有配置加载程序来处理此文件。”

我正在使用 MiniCssExtractPlugin 并具有以下 web 包配置来加载 css -


const MiniCssExtractPlugin = new _MiniCssExtractPlugin({
  filename: "[name].bundle.css",
  chunkFilename: "[id].css",
});

AND 

test: /\.css$/,
  exclude: /node_modules/,
  use: [
    {
      loader: MiniCssExtractPlugin.loader,
      options: {
        publicPath: __dirname + "/../../public/css/",
      },
    },
    {
      loader: "css-loader",
      options: {
        importLoaders: 1,
        modules: {
          localIdentName: "[name]__[local]___[hash:base64:5]",
        },
      },
    },
    {
      loader: "postcss-loader",
      options: {
        config: {
          path: __dirname + "/postcss.config.js",
        },
      },
    },
  ],
}

标签: javascriptreactjsnpmwebpack

解决方案


推荐阅读