问题
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/usage/initializing-slidebars/
I have installed the library with NPM.
npm install slidebars --save-dev
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();
});
run npm run watch
but then in my browser I get the following error in the console:
ReferenceError: slidebars is not defined
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.
回答1:
Run...
npm install slidebars
+ slidebars@2.0.2
added 1 package and audited 16905 packages in 9.487s
found 0 vulnerabilities
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) {}
Then compile the assets:
npm run prod
来源:https://stackoverflow.com/questions/55696234/import-a-library-dependency-with-laravel-mix