【问题标题】:How to use bootstrap 5 with webpack loader?如何将 bootstrap 5 与 webpack 加载器一起使用?
【发布时间】:2022-01-24 03:49:29
【问题描述】:

我正在使用带有 webpack 的 django 进行反应,这是第一次这样做,但我遇到了 webpack loader 的问题,它说:

ERROR in ./node_modules/bootstrap/dist/css/bootstrap.rtl.min.css 1:0
Module parse failed: Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> @charset "UTF-8";/*!
|  * Bootstrap v5.1.3 (https://getbootstrap.com/)
|  * Copyright 2011-2021 The Bootstrap Authors
 @ ./src/components/siteNavbar.js 4:0-50
 @ ./src/App.js 4:0-49 14:40-50
 @ ./src/index.js 1:0-28

这是我的webpack.config.js 文件:


const path = require("path");
const webpack = require("webpack");

module.exports = {
    entry: "./src/index.js",
    output: {
        path: path.resolve(__dirname, "./static/frontend"),
        filename: "[name].js",
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader",
                },
            },
        ],
    },
    optimization: {
        minimize: true,
    },
    plugins: [
        new webpack.DefinePlugin({
            "process.env": {
                // This has effect on the react lib size
                NODE_ENV: JSON.stringify("production"),
            },
        }),
    ],
};

我也在用babel 你能告诉我如何配置我的 webpack 文件以适应 bootstrap、字体真棒等等。

【问题讨论】:

    标签: reactjs django webpack


    【解决方案1】:

    我发现了我的问题,很抱歉,但我还是 webpack 的新手。

    我只是安装这些包:

    1. npm install sass-loader sass webpack --save-dev
    2. npm install --save-dev postcss-loader postcss

    然后我只是将我的webpack.config.js 文件编辑成这样:

    const path = require("path");
    const webpack = require("webpack");
    
    module.exports = {
        entry: "./src/index.js",
        output: {
            path: path.resolve(__dirname, "./static/frontend"),
            filename: "[name].js",
        },
        module: {
            rules: [
                {
                    test: /\.js$/,
                    exclude: /node_modules/,
                    use: {
                        loader: "babel-loader",
                    },
                },
                {
                    test: /\.css$/,
                    use: [
                        'style-loader',
                        'css-loader'
                    ]
                }
            ],
        },
        optimization: {
            minimize: true,
        },
        plugins: [
            new webpack.DefinePlugin({
                "process.env": {
                    // This has effect on the react lib size
                    NODE_ENV: JSON.stringify("production"),
                },
            }),
        ],
    };
    

    【讨论】:

      猜你喜欢
      • 2017-12-09
      • 2019-01-19
      • 2021-08-22
      • 2021-02-22
      • 1970-01-01
      • 1970-01-01
      • 2021-08-21
      • 1970-01-01
      • 2015-09-15
      相关资源
      最近更新 更多