jquery-match-height icon indicating copy to clipboard operation
jquery-match-height copied to clipboard

Plugin not working with webpack require

Open fearrr opened this issue 7 years ago • 4 comments

Plugin is not working with webpack require or import. After require $.fn.matchHeight not defined.

show-category.js:7 Uncaught TypeError: $(...).matchHeight is not a function

fearrr avatar Jul 19 '17 23:07 fearrr

+1

camdagr8 avatar Jul 21 '17 18:07 camdagr8

I got this package working fine in my webpack setup with the following:

webpack.config.js:

const webpack = require('webpack')

module.exports = {
  externals: {
    'jquery': 'jQuery'
  },
  plugins: [
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery',
      'window.jQuery': 'jquery'
    })
  ],
};

(Note that's just a fragment of my webpack setup, using it standalone wont work ⚠️ )

app.js (where I wanted to include matchheight):

import 'jquery-match-height'

Hope it helps! 🙂

breadadams avatar Sep 08 '17 20:09 breadadams

Awesome, this helped.

camdagr8 avatar Sep 14 '17 02:09 camdagr8

If what @breadadams says works, then maybe just this might also work in your webpack.config.js?

  externals: {
    'jquery': {
      commonjs: 'jquery',
      commonjs2: 'jquery',
      amd: 'jquery',
      root: 'jQuery'
    }
  }

Does anybody know if there's an easy change to the plugin that will mean this isn't needed?

liabru avatar Sep 17 '17 15:09 liabru