Webpack3.x 通过Webpack加载Bootstrap的CSS/Scss/JS 及更改CSS样式

本文详细介绍了如何在Webpack3.x中加载Bootstrap的CSS、Scss和JS,包括解决Icon fonts加载问题,引入jQuery,并在生产环境中处理静态资源。此外,还展示了如何更改Bootstrap的CSS样式,通过启用预Bootstrap自定义并创建自定义Scss文件实现。
摘要由CSDN通过智能技术生成

如何用webpack去加载bootstrap的css/scss 及JS呢,先准备一个bootstrap 模板b-index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-md-4">
                <p><img src=<%= require("./images/bootstrap.png")%>/></p>
            </div>
            <div class="col-md-8">
                <h1>Webpack 3 and Twitter Bootstrap</h1>
                <h2>How to configure Webpack 3 to load Twitter Bootstrap SCSS and JavaScript?</h2>
                <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
                    Launch demo modal
                </button>

                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel">Modal title</h4>
            
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 在./src/plugins/index.js中,可以使用require('bootstrap/dist/css/bootstrap.min.css')来引入bootstrap/dist/css/bootstrap.min.css文件。 ### 回答2: 要解决 "bootstrap/dist/css/bootstrap.min.css in ./src/plugins/index.js" 的问题,可以使用以下方法: 1. 确保项目中已经正确安装了 Bootstrap 库。可以运行 npm install bootstrap 命令来安装 Bootstrap,或者在项目的 package.json 文件中添加 Bootstrap 的依赖项。 2. 检查文件路径是否正确。确保文件路径 "./src/plugins/index.js" 是正确的,并且文件确实存在于该路径下。如果文件路径不正确,可以尝试修正路径中的拼写错误或者文件的实际位置。 3. 确保正确引入了 Bootstrap CSS 文件。在 "./src/plugins/index.js" 文件中,检查是否使用了正确的相对路径来引入 BootstrapCSS 文件。应该使用相对于当前文件的路径来引入 Bootstrap CSS 文件,例如 "../node_modules/bootstrap/dist/css/bootstrap.min.css"。 4. 确保 webpack 配置正确。如果使用 webpack 来构建项目,需要在 webpack 配置文件中添加对 CSS 文件的处理。查找 webpack 配置文件(通常是 webpack.config.js)中的模块配置,确保正确设置了处理 CSS 文件的 loader,例如使用 style-loader 和 css-loader。 5. 如果以上步骤都没有解决问题,可能是由于其他依赖项的冲突或不兼容性造成的。可以通过运行 npm update 命令来更新项目的依赖项,或者检查并解决其他依赖项的版本冲突。 总之,要解决 "bootstrap/dist/css/bootstrap.min.css in ./src/plugins/index.js" 的问题,需要确保正确安装了 Bootstrap,文件路径正确,正确引入 CSS 文件,并且正确配置webpack
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值