Laravel Elixir错误的路径

时间:2016-01-27 13:14:29

标签: laravel laravel-elixir

这是我的gulpfile.js

class TwoHellosList implements List<String> {

    @Override
    public int size() {
        return 2;
    }

    @Override
    public boolean isEmpty() {
        return false;
    }

    @Override
    public boolean contains(Object o) {
        return o.toString().equals("Hello");
    }

    @Override
    public Iterator<String> iterator() {
        return new Iterator<String>() {
            int count = 0;

            @Override
            public boolean hasNext() {
                return count < 2;
            }

            @Override
            public String next() {
                count += 1;
                return "Hello";
            }

        };
    }

    // The rest for you to complete.

    @Override
    public Object[] toArray() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public <T> T[] toArray(T[] a) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean add(String e) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean remove(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean addAll(Collection<? extends String> c) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean addAll(int index, Collection<? extends String> c) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void clear() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public String get(int index) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public String set(int index, String element) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void add(int index, String element) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public String remove(int index) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int indexOf(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int lastIndexOf(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ListIterator<String> listIterator() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ListIterator<String> listIterator(int index) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<String> subList(int fromIndex, int toIndex) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}

结果我得到了文件

公共/建造/ APP-2a14246111.css
公共/编译/ APP-7790e07dfb.js
public / build / rev-manifest.json

但是当我尝试将css和js文件添加到布局

var elixir = require('laravel-elixir');

elixir(function(mix) {
    mix.less([
       'style.less'
    ], 'public/css/style.css')
        .styles([
       'reset.css',
       'font-awesome.min.css',
       'style.css'
    ], 'public/css/app.css', 'public/css')
    .scripts(['jquery-1.12.0.min.js', 'main.js'], 'public/js/app.js', 'resources/assets/scripts')
    .version(['css/app.css', 'js/app.js']); 
});

我得到了

<link rel="stylesheet" href="{{ elixir("css/app.css") }}">    
<script src="{{ elixir("js/app.js") }}"></script> 

并且浏览器无法找到它们,因为它试图找到

<link rel="stylesheet" href="/build/css/app-2a14246111.css">
<script src="/build/js/app-7790e07dfb.js"></script>

项目文件夹名称和公用文件夹在路径中以某种方式丢失。如何解决?

实际上我看到了,我可以在

这样的路径中添加点
http://localhost:8080/build/css/app-2a14246111.css
http://localhost:8080/build/js/app-7790e07dfb.js

然后一切都会奏效,但我不喜欢这种解决方法。

2 个答案:

答案 0 :(得分:3)

那是因为你在localhost上运行Laravel项目。将项目部署到服务器时,问题会自行解决(假设已正确配置)。

如果您正在使用Apache,则可以添加虚拟主机配置,以便http://localhost:8080/laravel/public代替http://domain-name.app,而不是<VirtualHost *:80> DocumentRoot "C:\Users\username\path\to\laravel\public" ServerName domain-name.app </VirtualHost>

127.0.0.1   domain-name.app

然后在你的主机文件中添加:

/css/somefile.css

这样,您就可以链接到HTML中的绝对路径,例如./css/somefile.css而不是EncryptCookies

来自Laravel的

Checkout Homestead,它有助于避免屁股上的很多痛苦。

答案 1 :(得分:3)

FWIW ...您也可以使用URL :: asset包装elixir标签,如下所示:

<link href="{{ URL::asset(elixir('css/app.css')) }}" rel="stylesheet">

这解决了我的问题,仍允许我在8888端口上运行。