首页 > 解决方案 > Webpack : 导入 CSS

问题描述

我的 CSS 有问题。我正在使用这个配置,我想通过在我的脚本中导入 CSS import '@fullcalendar/core/main.css';

我有以下错误:

        Module parse failed: Unexpected character '@' (1:0)
        You may need an appropriate loader to handle this file type.
        @charset "UTF-8";
        | .fc {
        |   direction: ltr;
        @ ./assets/js/admin/admin.js 4:0-37

谢谢你的帮助。

标签: javascriptwebpackfullcalendar

解决方案


下面的配置对我有用

module: {
        rules: [{
                test: /\.css$/,
                use: [
                    'style-loader',
                    MiniCssExtractPlugin.loader,
                    {
                        loader: "css-loader",
                        options: {
                            minimize: true,
                            sourceMap: true
                        }
                    }
                ]
            }
        ]
    }

然后在你的js文件中导入这样的东西

import "css/Admin/admin.css";

推荐阅读