简体   繁体   English

使用mix将jquery stellar插件添加到laravel 5.4项目中

[英]add jquery stellar plugin to laravel 5.4 project using mix

I am new using Laravel Mix, I cant' add the jquery library stellar, it show me this error, when I try npm run dev : This dependency was not found: * jquery.stellar in ./resources/assets/js/bootstrap.js 我是新用的Laravel Mix,我不能'添加jquery库stellar,它告诉我这个错误,当我尝试npm run dev :找不到这个依赖:* jquery.stellar in ./resources/assets/js/bootstrap。 JS

But I already installed it using npm install --save jquery.stellar or npm install jquery.stellar 但我已经使用npm install --save jquery.stellarnpm install jquery.stellar安装了它

this is my webpack file: webpack.mix.js: 这是我的webpack文件:webpack.mix.js:

const { mix } = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/assets/js/app.js', 'public/js')
   ;

app.js: app.js:

/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

/*Ie10 windows phone fix*/
(function() {
  if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
    var msViewportStyle = document.createElement("style");
    msViewportStyle.appendChild(
      document.createTextNode("@-ms-viewport{width:auto!important}")
    );
    document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
  }
})();


/*Android fix*/
$(function () {
  var nua = navigator.userAgent
  var isAndroid = (nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1 && nua.indexOf('Chrome') === -1)
  if (isAndroid) {
    $('select.form-control').removeClass('form-control').css('width', '100%')
  }
});

/*my code*/
$(document).ready(function () {                

    $('.navbar-toggle').click(function () {
        $('.row-offcanvas').toggleClass('active');
    });        

    var w = $(window);
    if (w.width() >= 768 ){
        $('body').removeClass('margin-body');
        $('nav[role="navigation"]').removeClass('navbar-fixed-top');        
    }else{
        $('body').addClass('margin-body');
        $('nav[role="navigation"]').addClass('navbar-fixed-top');        
    }          

    $(window).stellar();    

});

bootstrap.js bootstrap.js

window.$ = window.jQuery = require('jquery');

require('jquery.stellar');

require('bootstrap-less');

And in my node_modules directory there is a jquery.stellar directory with 3 files in it: README.md,jquery.stellar.js, package.js 在我的node_modules目录中有一个jquery.stellar目录,里面有3个文件:README.md,jquery.stellar.js,package.js

I dont know what is happening, thank you. 我不知道发生了什么,谢谢。

Here is how you can add jquery.stellar! 以下是添加jquery.stellar的方法!

Assuming that you already installed stellar as your dependency You just have to write this line require( 'jquery.stellar/jquery.stellar' ); 假设你已经安装了stellar作为你的依赖你只需要写这行require( 'jquery.stellar/jquery.stellar' ); or require( 'jquery.stellar/jquery.stellar.js' ); 或者require( 'jquery.stellar/jquery.stellar.js' ); both works fine 两者都很好

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

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