Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integranting OwlCarousel2 + Webpack4 #2415

Open
eltonfms opened this issue Aug 10, 2018 · 1 comment
Open

Integranting OwlCarousel2 + Webpack4 #2415

eltonfms opened this issue Aug 10, 2018 · 1 comment

Comments

@eltonfms
Copy link

eltonfms commented Aug 10, 2018

Uncaught TypeError: Cannot read property 'fn' of undefined

webpack.config.js

const webpack = require('webpack');
const path = require('path');

const HtmlWebPackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
    module: {
        rules: [
            {
                test: /\.scss$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    "css-loader",
                    "postcss-loader",
                    "sass-loader"
                ]
            },
            {
                type: 'javascript/auto',
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader"
                }
            },
            {
                test: /\.html$/,
                use: [{
                    loader: "html-loader",
                    options: { minimize: false }
                }]
            },
            {
                test:/\.(png|jpg|gif)$/,
                use:[{
                    loader:'file-loader',
                    options:{ }
                }]
            }
        ]
    },
    plugins: [
        new webpack.ProvidePlugin({
            '$': 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
            'owl-carousel': 'owl-carousel.js'
        }),
        new HtmlWebPackPlugin({
            template: "./src/index.html",
            filename: "./index.html"
        }),
        new MiniCssExtractPlugin({
            filename: "[name].css",
            chunkFilename: "[id].css"
        })
    ]
};

index.js

import $ from 'jquery';
import jQuery from 'jquery';

import 'owl.carousel';

$(document).ready(function(){
    $(".owl-carousel").owlCarousel();
});

JQuery version: 3.3.1
OwlCarousel version: 2.3.4
Webpack version: 4.16.5

Note: jQuery is working correctly.

@mitkovalkov
Copy link

Try to add this in plugins: [] in webpack.config. It's work fine for me!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants