1

I am using laravel elixir and assign version like that

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

And I call it in meta tag like that

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

The result in meta tag is

 <link href="/build/assets/css/all-5ca511c0.css" rel="stylesheet" type="text/css">

I would like to learn is there any way to chang path like

<link href="assets/css/all-5ca511c0.css" rel="stylesheet" type="text/css">

Shortly I want to remove "build" from path. Thanks for advance

2 Answers 2

2

As of Laravel 5.2, Elixir has an option to set a custom path but it is not documented. To use the public folder without a build subfolder, you could use:

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 gives a nice explanation and a workaround for Laravel versions prior to 5.2.

Sign up to request clarification or add additional context in comments.

Comments

0

Here's how elixir() helper function is done, at 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.");
    }
}

Approach 1

As you can see, it only defines this function if it doesn't exists. So one way to go about it would be to define it with your own custom code and make sure that composer autoloader loads it first. But, it can get a little bit trick, so I suggest another approach:

Approach 2

Create your own helper function (with another name)! Just name it whatever you want, remove the two build references and use it. And also, make sure to check the original function from times to times to make sure that your code is compliant.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.