使用Laravel Mix导入库/依赖项 [英] Import a library/dependency with Laravel Mix

查看:71
本文介绍了使用Laravel Mix导入库/依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题,需要一些时间才能找到解决方案.我正在尝试将此库导入Laravel中的项目.

I have a small problem that took some time to find a solution. I'm trying to import this library to my project in Laravel.

> https://www.adchsm.com/slidebars/help/用法/initializing-slidebars/

我已经用NPM安装了该库.

I have installed the library with NPM.

npm install slidebars --save-dev

然后,我尝试将此库导入到我的 app.js 文件中,该文件具有以下结构:

Then I'm trying to import this library to my app.js file which has the following structure:

import jquery from 'jquery';
import popper from "popper.js";

try {
    window.$ = window.jQuery = jquery;
    window.Popper = popper.default;

    require('bootstrap');
    require('slidebars');

} catch (exception) {
    console.log(exception);
}

$(document).ready(function () {
    let constructor = new slidebars();
});

运行 npm run watch ,但是随后在浏览器中,我在控制台中收到以下错误:

run npm run watch but then in my browser I get the following error in the console:

ReferenceError:slidebars 未定义

请帮忙,如果您能帮助我,我已经在其他地方进行了搜索,但找不到解决方案.提前非常感谢您.

Please, if you could help me, I have searched in different places, but I can not find a solution for it. Thank you very much in advance.

推荐答案

运行...

npm install slidebars

+ slidebars@2.0.2
added 1 package and audited 16905 packages in 9.487s
found 0 vulnerabilities

在/resources/js/app.js中添加...

In /resources/js/app.js add...

window._ = require('lodash');

try {
    window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');
    window.slidebars = require('slidebars');

    require('bootstrap');
} catch (e) {}

然后编译资产:

npm run prod

这篇关于使用Laravel Mix导入库/依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆