简体   繁体   English

使用 jquery 的 Gulp 脚本不起作用

[英]Gulp scripts with jquery doesn't work

I try to use gulp in my new laravel project.我尝试在我的新 Laravel 项目中使用 gulp。 Laravel uses by default the laravel-elixir package. Laravel 默认使用laravel-elixir包。

Here is is gulpfile.js:这是 gulpfile.js:

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

elixir(function(mix) {
  mix
    .sass([
      "app.scss"
    ])
    .scripts([
      "vendor/jquery-2.1.4.min.js",
      "app.js",
    ], 'public/js/app.js')
    .version([
      "css/app.css",
      "js/app.js",
    ]);
});

After running gulp in the terminal and visiting the page, the css file is successfully loading but I get a 403 error while loading the js file.在终端中运行 gulp 并访问页面后,css 文件已成功加载,但在加载 js 文件时出现 403 错误。 I include the version build of the js via <script src="{{ elixir('js/app.js') }}"></script> and the file which wants to load exists.我通过<script src="{{ elixir('js/app.js') }}"></script>包含了 js 的版本构建,并且要加载的文件存在。 If i remove the line where I include jquery, everything works fine.如果我删除包含 jquery 的行,则一切正常。

I can fix this problem temporary by running chmod -R 777 public/build/ but after running gulp again I get the same error again.我可以通过运行chmod -R 777 public/build/临时解决这个问题,但是在再次运行gulp后,我再次遇到相同的错误。

Any ideas how to fix this problem?任何想法如何解决这个问题?

After hours of testing I found the solution.经过数小时的测试,我找到了解决方案。

The jquery file in resources/assets/js/vender has 640 permissions. resources/assets/js/vender的 jquery 文件有 640 个权限。 It looks like that the permissions are taken for the first file in the scripts array.看起来权限是为脚本数组中的第一个文件获取的。 I changed the jquery permissions to 664 and now it works fine.我将 jquery 权限更改为 664,现在它工作正常。

i had the same issues i solve it by run '/libs/jquery.js' in the beginner of the script我遇到了同样的问题,我通过在脚本的初学者中运行“/libs/jquery.js”来解决它

 elixir(function(mix) { mix.sass('app.scss'). styles([ 'libs/blog-post.css', 'libs/bootstrap.min.css', 'libs/font-awesome.min.css', 'libs/font-awesome.css', 'libs/styles.css', ],'./public/css/libs.css'). scripts([ 'libs/jquery.js', 'libs/bootstrap.js', 'libs/bootstrap.min.js', 'libs/scripts.js', ],'./public/js/libs.js'); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM