Elixir versioning public path

爷,独闯天下 提交于 2019-12-03 12:25:33

You forgot to overwrite your publicDir folder in the gulpfile.js file, this points the build folder to the correct location which is used by elixir to determine the version hash.

elixir.config.publicDir = 'public_html';

After you did that you must overwrite your public_path in Laravel, the recommended way for Laravel 5 is to go to the index.php in your public folder:

Underneath

$app = require_once __DIR__.'/../bootstrap/app.php';

Add

// set the public path to this directory
$app->bind('path.public', function() {
    return __DIR__;
});

all you need do is this

var elixir = require('laravel-elixir');
elixir.config.publicDir = 'public_html';
elixir.config.publicPath = 'public_html';

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. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!