使用 composer 将 Bootstrap-4 安装到 Laravel 5.5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48042437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing Bootstrap-4 to Laravel 5.5 using composer
提问by hamzaerdem
I created a Laravel project using
我创建了一个 Laravel 项目使用
composer create-project --prefer-dist laravel/laravel myProject
Then I installed Bootstrap-4 using
然后我安装了 Bootstrap-4 使用
composer require twbs/bootstrap:4.0.0-beta.3
My bootstrap dist directory is
我的引导程序 dist 目录是
vendor/twbs/bootstrap/dist
I copied bootstrap-min.css to public/css directory. Then I added this line in my head tags
我将 bootstrap-min.css 复制到 public/css 目录。然后我在我的 head 标签中添加了这一行
<link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet">
But Bootstrap-4 is not working on my page. Which file has to be changed now?
但是 Bootstrap-4 在我的页面上不起作用。现在必须更改哪个文件?
采纳答案by Rob Fonseca
Copying composer files directly into your public folder is generally bad practice. Not only is the public/cssfolder in the .gitignore file so it will break when you port over to production, any downloaded updates will not be applied if you update the package.
将作曲家文件直接复制到您的公共文件夹中通常是不好的做法。不仅是.gitignore 文件中的public/css文件夹,所以当你移植到生产环境时它会损坏,如果你更新包,任何下载的更新都不会应用。
Laravel News has made a front end preset for Bootstrap 4. Laravel 5.6 will have Bootstrap 4 as a preset option baked in, but for now, this is the way to go https://laravel-news.com/bootstrap-4-laravel-preset/
Laravel News 为 Bootstrap 4 做了一个前端预设。 Laravel 5.6 将把 Bootstrap 4 作为一个预设选项,但现在,这是要走的路https://laravel-news.com/bootstrap-4-laravel -预设/
You could also just use Bootstrap straight from the CDN
您也可以直接从 CDN 使用 Bootstrap
回答by dbrumann
When you install bootstrap via composer it's put in the vendor/ folder, which is not accessible by your webserver. You have to copy or symlink the css and js into your public/ directory:
当您通过 Composer 安装 bootstrap 时,它被放在 vendor/ 文件夹中,您的网络服务器无法访问该文件夹。您必须将 css 和 js 复制或符号链接到您的 public/ 目录中:
cp vendor/twbs/bootstrap/css/bootstrap.min.css public/css/bootstrap.min.css
cp vendor/twbs/bootstrap/js/bootstrap.min.js public/js/bootstrap.min.js
Since bootstrap is a frontend dependency I would instead use gulp or maybe Symfony's Webpack Encore for managing this: https://symfony.com/doc/current/frontend/encore/bootstrap.html
由于引导程序是前端依赖项,我会改为使用 gulp 或 Symfony 的 Webpack Encore 来管理它:https://symfony.com/doc/current/frontend/encore/bootstrap.html
Webpack Encore is a standalone component that should not require any modifications in your laravel appand does not rely on any other Symfony component as far as I know. If that is a concern you have.
据我所知,Webpack Encore 是一个独立的组件,不需要在您的 Laravel 应用程序中进行任何修改,并且不依赖于任何其他 Symfony 组件。如果这是你的顾虑。