Webpack dependent plugin

128 Views Asked by At

i am trying to add sammyjs on webpack as a plugin. But sammyjs is dependent on jquery and jquery is also present on plugin.

Here is the code

const webpack = require('webpack')
const jquery = require('jquery')
const Sammy = require('sammy')
const {resolve} = require('path')

    const webpackConfig = {

        entry: "./src/js/bootstrap.js",
        output: {
            path: resolve("dist"),
            filename: "bundle.js",
            publicPath: '/dist/'
        },
        plugins: [
            new webpack.ProvidePlugin({
                $: 'jquery',
                jQuery: 'jquery',
                'window.jQuery': 'jquery',
                Sammy: 'Sammy'
            })
        ],
        module: {
            rules: [
                {
                    test: /\.js$/,
                    exclude: /node_modules/,
                    use: {
                        loader: "babel-loader"
                    }
                }
            ]
        },
        resolve: {
            alias: {
                graph: resolve(__dirname, 'src/modules/graph'),
            }
        },
    };

    module.exports = webpackConfig;

but building it. Sammyjs keeps asking for jQuery variable:

enter image description here

I dont just want to import it in pages because it feels like the bundle is getting bigger.

Please tell me if i am doing right. Or there is other way to attain clean and smaller bundle.

0

There are 0 best solutions below