Laravel Elixir错误的路径 [英] Laravel Elixir wrong paths
问题描述
这是我的gulpfile.js
This is my gulpfile.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']);
});
结果我得到了文件
public/build/app-2a14246111.css
public/build/app-7790e07dfb.js
public/build/rev-manifest.json
public/build/app-2a14246111.css
public/build/app-7790e07dfb.js
public/build/rev-manifest.json
但是当我尝试将css和js文件添加到布局中
but when I try to add css and js files to layout
<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>
浏览器找不到它们,因为它试图找到
and browser can't find them because it tries to find
http://localhost:8080/build/css/app-2a14246111.css
http://localhost:8080/build/js/app-7790e07dfb.js
以及项目文件夹名称和公用文件夹在路径中以某种方式丢失.如何解决?
and project folder name and public folder are missed somehow in paths. How to fix it?
实际上,我可以在路径中添加点
Actually I see, I can add dot in paths like
<link rel="stylesheet" href=".{{ elixir("css/app.css") }}">
<script src=".{{ elixir("js/app.js") }}"></script>
然后一切都会起作用,但是我不喜欢这种修复方法.
and then all will work, but I don't like this kind of fix.
推荐答案
那是因为您正在本地主机上运行Laravel项目.将项目部署到服务器时,问题会自行解决(假设已正确配置).
That's because you're running the Laravel project on localhost. When you deploy the project to a server, the problem resolves itself (assuming it's configured correctly).
如果使用的是Apache,则可以添加虚拟主机配置,以便可以使用http://domain-name.app
代替:
If you're using Apache, you can add a Virtual Host configuration so that instead of http://localhost:8080/laravel/public
you can use something like http://domain-name.app
:
<VirtualHost *:80>
DocumentRoot "C:\Users\username\path\to\laravel\public"
ServerName domain-name.app
</VirtualHost>
然后在您的主机文件中添加:
And then in your hosts file add:
127.0.0.1 domain-name.app
这样,您可以链接到HTML中的绝对路径,例如/css/somefile.css
而不是./css/somefile.css
.
This way, you can link to absolute paths in your HTML like /css/somefile.css
instead of ./css/somefile.css
.
从Laravel结帐宅基地,它可以避免很多麻烦.
Checkout Homestead, from Laravel, it helps to avoid a lot of pain in the ass.
这篇关于Laravel Elixir错误的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!