2017-03-15 13 views
3

我是新使用Laravel混合到laravel 5.4的項目,我不能」添加jQuery庫恆星,它給我這個錯誤,當我嘗試NPM運行開發: 此相關性沒有被發現: * jquery.stellar在我已經安裝使用NPM安裝--save jquery.stellarNPM它./resources/assets/js/bootstrap.js加入jQuery的恆星插件使用混合

但安裝jquery.stellar

這是我的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:

/** 
* 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

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

require('jquery.stellar'); 

require('bootstrap-less'); 

在我node_modules目錄中有一個在它的3個文件一jquery.stellar目錄:README.md, jquery.stellar.js,package.js

我不知道發生了什麼,謝謝。

回答

0

這裏是你如何添加jquery.stellar!

假設你已經安裝的恆星作爲你的依賴 你只需要在此線require('jquery.stellar/jquery.stellar');require('jquery.stellar/jquery.stellar.js');都工作正常