D
D
Dymok2018-06-25 01:52:54
JavaScript
Dymok, 2018-06-25 01:52:54

How to include jQuery plugins in Webpack?

Hello. I'm trying to connect the isotope filter to webpack. Installed it with npm, trying to import and use:

spoiler
import $ from 'jquery';
import "isotope-layout";

var $grid = $(".our-design__gallery-items").isotope({
    itemSelector: '.our-design__gallery-item',
});

$(".our-design__gallery-filters").on("click", "li", function(){
    $grid.isotope({ filter: $(this).attr('data-filter') });
});

webpack.config
// webpack.config.js
var webpack = require('webpack');

module.exports = {
    mode: 'development',
    entry: './src/js/entry.js',
    output: {
        filename: 'bundle.js',
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /(node_modules)/,
                loader: 'babel-loader',
                query: {
                    presets: [
                        ['env', {modules: false}],
                    ],
                },
            },{

            }
        ],
    },
    plugins: [
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery'
        }),
    ],
    devtool: 'source-map'
};

But at the same time, an error appears in the console:
Uncaught TypeError: jquery__WEBPACK_IMPORTED_MODULE_0___default(...)(...).isotope is not a function

Although in the assembled bundle, isotope connects and connects before it is called. Tell me, please, what am I doing wrong? Thank you.

Answer the question

In order to leave comments, you need to log in

8 answer(s)
P
profesor08, 2018-06-25
@profesor08

Jquery is a dinosaur, which is how you want to use it will not work. Need plugins.
https://webpack.js.org/plugins/provide-plugin/

F
Froggyweb, 2018-06-25
@Froggyweb

isotope.metafizzy.co.s3-website-us-east-1.amazonaw...
See documentation

V
Vadim Kyssa, 2014-10-09
@cissav

A very correct approach. This is exactly how a startup should be promoted. Still, potential customers are just waiting to be spammed about a cool new startup.
Be prudent. Few people are tolerant of spam. Most, even if they look at your startup, they definitely won’t want to buy. Why pay for a service that promotes itself so seriously.

S
Sergey Sokolov, 2014-10-09
@sergiks

Purchased bases are likely to have a very low response: you will get more problems with spam complaints than customers.
It's better to attract traffic with a virus of profit: making everyone who knows interested in attracting more people. Whether it's an iPhone raffle contest (honestly give away 1-2 sixths, or a few 5c is comparable to the purchase price of the base), the chances of winning grow in proportion to the number of people attracted by the participant. Or an opportunity for anyone to earn on the next referrals.
 

K
Konstantin Andreevich, 2014-10-09
@reffy

With the help of spam, you can only drive traffic to a startup that offers earnings from $ 700 per day without investment, working 3 hours a day.

F
firemark_s, 2014-10-09
@firemark_s

Write to me
or Skype dial sol_47

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question