2015-04-07 66 views
8

我正在嘗試使用Elixir的version()方法,將我的'public'文件夾設置爲public_html(而不是默認的'public'方法)。Elixir版本控制公共路徑

我的版本我的CSS文件,其產生的build文件夾中的清單內的public_html

elixir.config.cssOutput = 'public_html/css'; 
elixir.config.jsOutput = 'public_html/js'; 

elixir(function(mix) { 

    mix.styles([ 
     'vendor/normalize.css', 
     'app.css' 
    ], null, 'public_html/css'); 

    mix.version('public_html/css/all.css'); 

}); 

在我的刀模板我用

<link href="{{ elixir("css/all.css") }}" rel="stylesheet"> 

問題是「公共的靈藥函數搜索/建立'文件夾。我怎樣才能改變它,所以它搜索public_html文件夾?

預先感謝您

+0

https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5 – lukasgeiter

+0

不改變仙丹配置文件中的公共路徑的任何方式? 我必須在/node_modules/laravel-elixir/ingredients/version.js之前將其更改! – Gregory

+0

'elixir()'使用'public_path()',所以你需要覆蓋'path.public',如後所示鏈接 – lukasgeiter

回答

10

您忘記覆蓋gulpfile.js文件中的publicDir文件夾,這會將build文件夾指向elixir用來確定版本哈希的正確位置。

elixir.config.publicDir = 'public_html'; 

後你做了,你必須覆蓋在Laravel你public_path,對於Laravel 5推薦的方法是去index.php在公共文件夾:

底下

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

添加

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

謝謝,我找到了解決方案,但已經忘記更新此線程。不管怎麼說,還是要謝謝你! – Gregory

+0

我添加這些行,但它似乎並沒有解決這個問題,它仍然會創建公共目錄(代替的public_html) – Roderik

+0

您還需要添加'elixir.config.publicPath =「的public_html」;'由Lordcash –

1

中有靈藥(),用於改變公共路徑別無選擇:

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

只有幾個選項。

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

然後你可以使用:您可以通過添加這個到App \供應商\ AppServiceProvider

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

,或者你可以創建自己的靈藥功能或輔助類

例改變公衆路徑這在後面的看法:

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

希望在未來的版本的elixir這未來e將包括在內。 :)

+1

該路徑不是*硬編碼*它使用Laravels全局配置'public_path',這是合理的。它可以很容易地被覆蓋。無需編寫您自己的功能。 (你也不必創建一個新的服務提供者,但可以使用AppServiceProvider) – lukasgeiter

+0

@lukasgeiter感謝Boss。我做了一些更正 – Digitlimit

+0

太棒了!+1。 – lukasgeiter

5

所有你需要做的就是這個

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

儘管此代碼可能回答這個問題,但提供關於此代碼爲何和/或如何回答問題的其他上下文可提高其長期價值。 – JAL