Elixir versioning public path

前端 未结 3 2324
日久生厌
日久生厌 2021-02-15 07:46

I\'m trying to use Elixir\'s version() method with my \'public\' folder being public_html (instead of the default \'public\' method).

I version my css file, which produc

3条回答
  •  不思量自难忘°
    2021-02-15 08:11

    There is no option in elixir() for changing the public path:

    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.");
        }
    

    There are only few options. You can change public path by adding this to App\Providers\AppServiceProvider

    public function register()
        {
            $this->app->bind('path.public', function() {
              return base_path().'/public_html';
            });
        }
    

    or you can create your own elixir function or a helper class

    Example:

        function my_own_elixir($file,$path=public_path())
                {
                    static $manifest = null;
    
                    if (is_null($manifest))
                    {
                        $manifest = json_decode(file_get_contents($path.'/build/rev-manifest.json'), true);
                    }
    
                    if (isset($manifest[$file]))
                    {
                        return '/build/'.$manifest[$file];
                    }
    
                    throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
                }
    

    Then you can use this later in view:

    {{my_own_elixir('/css/all.css',$path='path to public_html')}}
    

    Hopefully in future version of elixir this future will be included. :)

提交回复
热议问题