A
A
Alexander2017-02-19 18:41:54
webpack
Alexander, 2017-02-19 18:41:54

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

2 answer(s)
K
KnightForce, 2017-02-21
@KnightForce

You download through the package manager.
For example npm install jQuery.
And in webpack.config:

new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery",
}),

As a result, call $ anywhere in the program and that's it.

A
amokrushin, 2017-02-20
@amokrushin

This is understandable, because this library does not use module.exports and therefore does not return anything.

This is not a library, but a jQuery plugin, which is designed as a UMD module , there is module.exports in the code , but it does not return anything, because it is not necessary.
Install first:
Then can be used like this:
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 question

Ask a Question

731 491 924 answers to any question