Search code examples
javascriptjquerywebpackmagnific-popup

magnificPopup is not working with webpack


I have installed magnificPopup via "npm i magnific-popup" command after that imported it in the app.js file. But in the browser console it shows (magnificPopup is not a function )

app.js

import $ from "jQuery";
window.$ = window.jQuery = $;
import "magnific-popup";

$(document).ready(function() {
    $('.play-btn').magnificPopup({ type: 'video' });

});

webpack.config.js

var path = require("path");
var webpack = require('webpack');


module.exports = {
    entry: {
        app: "./app/assets/scripts/app.js",
        vendor: "./app/assets/scripts/vendor.js"
    },
    output: {
        path: path.resolve(__dirname, "./app/temp/scripts"),
        filename: "[name].js"
    },
    module: {
        rules: [{
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ["es2015"]
                    }
                }
            }

        ]
    },
    plugins: [
        new webpack.ProvidePlugin({
            '$': 'jquery',
            'jQuery': 'jquery',
            'window.jQuery': 'jquery'
        }),
    ]
}

Solution

  • I've fixed the problem

    jQuery doesn't need to import in app.js

    After fixing app.js file looks like this

    import "magnific-popup";
    
    $(document).ready(function() {
        $('.play-btn').magnificPopup({ type: 'video' });
    
    });