使用Laravel 5.7进行Bootstrap 4安装

Pab*_*aco 4 npm laravel laravel-5 bootstrap-4 laravel-5.7

我正在尝试从Laravel编译新项目随附的app.scss文件,但我想安装Bootstrap4。在执行此操作时,我npm run dev没有安装Bootstrap 4,但默认情况下它仍然具有Laravel带来的Bootstrap。 。

有什么建议或文档吗?

在此处输入图片说明

Mar*_*łek 7

实际上,Laravel默认随附Bootstrap 4。如果您查看 https://github.com/laravel/laravel/blob/master/package.json文件(您的项目中也应该有package.json),您将看到以下行:

"bootstrap": "^4.0.0"
Run Code Online (Sandbox Code Playgroud)

这意味着将安装Bootstrap 4。

你应该跑

npm install
Run Code Online (Sandbox Code Playgroud)

安装所有软件包,默认情况下它将安装Bootstrap 4。

这个~符号表示这里的node_modules目录,因此实际上是

@import "~bootstrap/scss/bootstrap"
Run Code Online (Sandbox Code Playgroud)

手段

@import "node_modules/bootstrap/scss/bootstrap"
Run Code Online (Sandbox Code Playgroud)


J. *_*son 7

如果查看Laravel welcome.blade.php文件,则可以看到一些CSS和导入Google字体的链接标记。请勿将其与实际导入Bootstrap 4混淆。

以下是实现Bootstrap 4以及默认情况下Laravel附带的所有其他有趣功能的步骤。好像您已经在运行,npm run watch所以我假设您已经在运行该命令。

简单步骤

将链接标签添加到您的head元素:

<link rel="stylesheet" href="css/app.css">
Run Code Online (Sandbox Code Playgroud)

Add the following at the bottom of your body element:

<script src="js/app.js" charset="utf-8"></script>
Run Code Online (Sandbox Code Playgroud)

That should do it for you. But please make sure you've compiled the SCSS files and Javascript files using the npm run watch command or else it won't work!

Cheers!