Skip to content

Instantly share code, notes, and snippets.

@mort3za
Last active December 14, 2020 07:14
Show Gist options
  • Save mort3za/2faf29064fd99784581a9a1497e90737 to your computer and use it in GitHub Desktop.
Save mort3za/2faf29064fd99784581a9a1497e90737 to your computer and use it in GitHub Desktop.
Add jQuery to window object in Webpack 4
import jQuery from 'jquery'
window.jQuery = window.$ = window.jquery = jQuery
module: {
    rules: [
      {
        test: require.resolve('jquery'),
        use: [
          {
            loader: 'expose-loader',
            options: 'jQuery'
          }
        ]
      },
    ]
},
plugins: [
  new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery',
      Mustache: 'mustache',
      'window.jQuery': 'jquery'
  })
]

Install package: "expose-loader": "0.7.5",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment