我正在使用laravel elixir并分配类似的版本
mix.version([
'public/assets/css/all.css',
'public/assets/js/all.js'
]);
我在元标签中称之为
{{ elixir('assets/css/all.css') }}
元标签中的结果是
<link href="/build/assets/css/all-5ca511c0.css" rel="stylesheet" type="text/css">
我想知道有没有办法像那样改变道路
<link href="assets/css/all-5ca511c0.css" rel="stylesheet" type="text/css">
很快,我想从路径中删除"build"。感谢提前
从Laravel 5.2开始,Elixir有一个设置自定义路径的选项,但没有文档记录。要使用没有生成子文件夹的公用文件夹,可以使用:
elixir(function(mix) {
mix.version(['css/all.css', 'js/all.js'], 'public');
});
// For referencing the css
// null -> base directory (public)
<link rel="stylesheet" href="{{ elixir('css/all.css', null) }}">
这篇博客文章为Laravel 5.2之前的版本提供了一个很好的解释和解决方法。
以下是如何在vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
:中完成elixir()
辅助函数
if ( ! function_exists('elixir'))
{
/**
* Get the path to a versioned Elixir file.
*
* @param string $file
* @return string
*/
function elixir($file)
{
static $manifest = null;
if (is_null($manifest))
{
$manifest = json_decode(file_get_contents(public_path().'/build/rev-manifest.json'), true);
}
if (isset($manifest[$file]))
{
return '/build/'.$manifest[$file];
}
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
}
}
方法1
正如您所看到的,它只在这个函数不存在的情况下定义它。因此,一种方法是用自己的自定义代码定义它,并确保composer autoloader首先加载它。但是,它可能会有一点小技巧,所以我建议另一种方法:
方法2
创建您自己的助手函数(使用另一个名称)!只需随意命名,删除两个build
引用并使用它。此外,请确保不时检查原始函数,以确保您的代码符合要求。