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

标签 javascript jquery node.js laravel-5 laravel-mix

我是 Laravel Mix 的新手,我无法添加 jquery 库 stellar,当我尝试 npm run dev 时,它向我显示了这个错误: 找不到此依赖项: * ./resources/assets/js/bootstrap.js 中的 jquery.stellar

但我已经使用 npm install --save jquery.stellarnpm install 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')
   ;

应用程序.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 目录中有一个 jquery.stellar 目录,里面有 3 个文件:README.md、jquery.stellar.js、package.js

我不知道发生了什么,谢谢。

最佳答案

这里是你可以添加 jquery.stellar 的方法!

假设你已经安装了 stellar 作为你的依赖 你只需要写这行 require( 'jquery.stellar/jquery.stellar' );require( 'jquery.stellar/jquery.stellar.js' ); 都可以正常工作

关于javascript - 使用 mix 将 jquery stellar 插件添加到 laravel 5.4 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42821291/

相关文章:

node.js - 在node js中发送到客户端后无法设置 header

javascript - 我的自动完成功能触发了太多次

mysql - 同步调用sql查询

javascript - 我想用(新的 promise )将数据存储在变量中? javascript

javascript - Angularjs $http 不发送表单数据到服务器

javascript - 使用 AJAX 将内容加载到 jQuery UI 对话框

jquery - jQuery/CSS3 中的屏幕闪烁效果

node.js - 使用 Digital Ocean 和 FlightPlan.js 时 Node 应用程序出错 - 所有配置的身份验证方法均失败

javascript - 如何检查表单中的所有空输入

javascript - 鼠标悬停时输入字段更新