【问题标题】:Change laravel elixir version path更改 laravel elixir 版本路径
【发布时间】:2015-04-02 09:08:46
【问题描述】:

我正在使用 laravel elixir 并分配这样的版本

mix.version([
    'public/assets/css/all.css',
    'public/assets/js/all.js'
]);

我在元标记中这样称呼它

{{ elixir('assets/css/all.css') }}

meta标签中的结果是

 <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">

很快我想从路径中删除“构建”。感谢提前

【问题讨论】:

    标签: php laravel laravel-elixir


    【解决方案1】:

    从 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) }}"> 
    

    This blogpost 为 Laravel 5.2 之前的版本提供了一个很好的解释和解决方法。

    【讨论】:

      【解决方案2】:

      elixir() 辅助函数是如何完成的,vendor/laravel/framework/src/Illuminate/Foundation/helpers.php

      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 自动加载器首先加载它。但是,它可能会有点技巧,所以我建议另一种方法:

      方法2

      创建您自己的辅助函数(使用另一个名称)! 只需将其命名为您想要的任何名称,删除两个 build 引用并使用它。此外,请确保不时检查原始函数以确保您的代码符合要求。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-18
        • 1970-01-01
        • 2015-04-27
        • 2015-06-11
        • 2017-01-20
        • 2015-09-14
        • 2017-12-17
        • 2017-11-28
        相关资源
        最近更新 更多