0

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.

Terry
  • 63,248
  • 15
  • 96
  • 118
  • Possible duplicate of [Managing jQuery plugin dependency in webpack](https://stackoverflow.com/questions/28969861/managing-jquery-plugin-dependency-in-webpack) – Terry Mar 23 '18 at 22:51
  • Thanks Terry. I did what is said on link. but the problem persist. – Joshua San Jose Mar 23 '18 at 23:06

0 Answers0