从 Laravel 5 视图访问供应商文件的简单而干净的方法是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31528611/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:59:25  来源:igfitidea点击:

What is an easy and clean way to access vendor files from a Laravel 5 view

laravellaravel-5

提问by user3489502

I've installed bootstrap-calendar(using bower) to my Laravel 5 project. Bootstrap-calendar got installed into my laravel/vendor/bootstrap-calendar/ folder.

我已经将bootstrap-calendar(使用 bower)安装到我的 Laravel 5 项目中。Bootstrap-calendar 已安装到我的 laravel/ vendor/bootstrap-calendar/ 文件夹中。

To use bootstrap-calendar, I need to reference CSS/JS files in my views, from:

要使用 bootstrap-calendar,我需要在我的视图中引用 CSS/JS 文件,来自:

laravel/vendor/bootstrap-calendar/css
laravel/vendor/bootstrap-calendar/js

Is there an easy and clean way to use these files in my project without having to copy them to the public folder?

是否有一种简单而干净的方法可以在我的项目中使用这些文件而无需将它们复制到公共文件夹?

采纳答案by Bogdan

The files outside of the publicdirectory are not available over HTTP (since publicis the server's Document Root). You have two options here:

目录外的文件public无法通过 HTTP 访问(因为public是服务器的文档根目录)。您在这里有两个选择:

  1. Copy the bootstrap-calendarfiles to your publicdirectory (not the best solution, because on any update of the package you would need to copy them again)

  2. Create a symbolic link from the vendor directory to a bootstrap-calendardirectory in publicusing the following command (make sure you create the bootstrap-calendardirectory in publicbeforehand):

  1. bootstrap-calendar文件复制到您的public目录(不是最好的解决方案,因为在包的任何更新时,您都需要再次复制它们)

  2. 使用以下命令创建从供应商目录到bootstrap-calendar目录的符号链接public(确保事先创建bootstrap-calendar目录public):

ln -s /path/to/laravel/vendor/bootstrap-calendar /path/to/laravel/public/bootstrap-calendar

Then you can include them in your view like so:

然后你可以像这样将它们包含在你的视图中:

<!-- Stylesheets -->
<link rel="stylesheet" href="{{ asset('bootstrap-calendar/css/calendar.css') }}">

<!-- Scripts -->
<script src="{{ asset('bootstrap-calendar/js/calendar.js') }}">

回答by ceejayoz

You can use Laravel Mix(known as Laravel Elixiron Laravel <= 5.3) to perform this and other functions on your app's assets.

您可以使用Laravel Mix(在 Laravel <= 5.3 上称为Laravel Elixir)在您的应用程序资产上执行此功能和其他功能。

Laravel >= 5.4:

Laravel >= 5.4:

mix.copy('vendor/bootstrap-calendar/css', 'public/bootstrap-calendar/css');
mix.copy('vendor/bootstrap-calendar/js', 'public/bootstrap-calendar/js');

Laravel <= 5.3:

Laravel <= 5.3:

elixir(function(mix) {
    mix.copy('vendor/bootstrap-calendar/css', 'public/bootstrap-calendar/css');
    mix.copy('vendor/bootstrap-calendar/js', 'public/bootstrap-calendar/js');
});