Answer the question
In order to leave comments, you need to log in
How to import jquery library in webpack?
There is a library in my slick slider project . I have a catalog.js file that imports the slider.js module, I want to add the code of this library to it, I tried to make the require('libs/slick/dist/slick.min') requester at the beginning of the file, but slider1 is written at the output. slick is not a function. This is understandable, because this library does not use module.exports and therefore does not return anything.
How does webpack usually include such libraries in the build? I understand through ProvidePlugin? Are there other methods? I just want to know what methods are used and which is generally better.
Answer the question
In order to leave comments, you need to log in
You download through the package manager.
For example npm install jQuery
.
And in webpack.config:
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
}),
This is understandable, because this library does not use module.exports and therefore does not return anything.
require('slick-carousel');
require('slick-carousel/slick/slick.css');
require('slick-carousel/slick/slick-theme.css');
const $ = require('jquery');
$(document).ready(function(){
$('.your-class').slick({
setting-name: setting-value
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question