在 CLI 中运行“gulp”后,Laravel 5 Elixir css/js 未进入 public/ 目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26500755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 Elixir css/js not coming into public/ directory after running 'gulp' in CLI
提问by JeffreyWay
I read the documentation available for Laravel 5's new Elixir.
我阅读了 Laravel 5 新 Elixir 的可用文档。
I have written this code and run gulp multiple times, however, the compiled/minified css and js are not coming in:
我已经编写了这段代码并多次运行 gulp,但是,编译/缩小的 css 和 js 没有进来:
var elixir = require('laravel-elixir');
elixir(function(mix) {
mix
.styles([
"resources/assets/components/bootstrap/dist/css/bootstrap.css"
])
.scripts([
"resources/assets/components/jquery/dist/jquery.js"
])
.version('css/app.css');
});
I've run npm install
and gulp
in the CLI and I get this output (which seems normal):
我已经在 CLI 中运行npm install
并gulp
得到了这个输出(这看起来很正常):
[05:15:58] Starting 'default'...
[05:15:58] Starting 'styles'...
[05:16:00] Finished 'default' after 1.32 s
[05:16:00] Finished 'styles' after 1.32 s
[05:16:00] Starting 'scripts'...
[05:16:00] Finished 'scripts' after 456 ms
[05:16:00] Starting 'version'...
[05:16:00] Finished 'version' after 2.6 ms
vagrant@homestead:~/Code/fixer$
What's the problem here? I also watched the Laracast and it seems I'm doing everything properly.
这里有什么问题?我还看了 Laracast,看来我做的一切都很好。
It's difficult to find a good answer given this is new.
鉴于这是新的,很难找到一个好的答案。
回答by JeffreyWay
Elixir will assume that the stylesheets and scripts that you're concatenating are located in the public/ directory. To override that, set the base directory.
Elixir 将假设您连接的样式表和脚本位于 public/ 目录中。要覆盖它,请设置基本目录。
elixir(function(mix) {
mix
.styles([
"components/bootstrap/dist/css/bootstrap.css"
], "resources/assets")
.scripts([
"components/jquery/dist/jquery.js"
], "resources/assets")
.version('css/app.css');
});
(But also remember that you're trying to concatenate one file in each of those blocks... Maybe that was just for your code snippet.)
(但也请记住,您正在尝试将每个块中的一个文件连接起来……也许那只是为了您的代码片段。)
回答by Joe
Check your package.json
file - I've been trying to fix this issue for myself this morning, and it turns out that Elixir is a little buggy at the moment.
检查您的package.json
文件 - 今天早上我一直在尝试为自己解决这个问题,结果证明 Elixir 目前有点问题。
I'd been trying to run multiple .scripts()
functions (one for head scripts, one for foot scripts) which didn't work until I found this postwhich said to update to version 0.4.x of Elixir. I did that, and suddenly the scripts seemed to be compiling.
我一直在尝试运行多个.scripts()
函数(一个用于头部脚本,一个用于脚部脚本),直到我发现这篇文章说更新到 Elixir 的 0.4.x 版后才起作用。我这样做了,突然之间脚本似乎正在编译。
Then they stopped appearing in /public/js
for no reason that I could find, and downgrading back to 0.3.* has made them come back.
然后他们/public/js
无缘无故地停止出现在我找不到的地方,降级到 0.3.* 使他们回来了。
My package.json
looks like this right now:
我package.json
现在看起来像这样:
{
"devDependencies": {
"gulp": "^3.8.9",
"laravel-elixir": "^0.3.*"
}
}
回答by Krisjanis
I have the same problem. Just started to debug this and so far I can tell that problem is caused by the fact that there is incorrect src variable passed to gulp-less from elixir:
我也有同样的问题。刚刚开始调试这个,到目前为止,我可以看出问题是由不正确的 src 变量从 elixir 传递给 gulp-less 引起的:
[ 'undefined/resources/assets/less/site.less' ]
As you can see, it is prefixed by "undefined".
如您所见,它以“未定义”为前缀。
If one would pass correct path string into the function (in GulpCssCompiler), then it works fine.
如果将正确的路径字符串传递给函数(在 GulpCssCompiler 中),那么它就可以正常工作。
return gulp.src('resources/assets/less/site.less')
.pipe(plugins[options.pluginName](options.pluginOptions))
I will look into this some more.
我会再研究一下。
EDIT: There seems to be an error in 'GulpCssCompiler.js' file. Short fix: Replace on line 11:
编辑:“GulpCssCompiler.js”文件中似乎有错误。简短修复:在第 11 行替换:
options.src, options.assetsDir, options.search
with:
和:
options.src, config.assetsDir, options.search
and use 'less/file.less' in gulpfile (this presumes that resources/assets is the assetsdir)
并在 gulpfile 中使用“less/file.less”(这假定资源/资产是资产目录)