2015-04-07 49 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