Skip to content

How to include jQuery

Phiphou edited this page Jun 24, 2016 · 7 revisions

npm install jquery --save-dev
typings install dt~jquery --save --global

  plugins: [
    new webpack.ProvidePlugin({
      jQuery: 'jquery',
      $: 'jquery',
      jquery: 'jquery'
    })
  ]

Note:

If you use vendor modules that depend on jQuery and if all of them don't use the same jQuery version, or if you use jQuery itself and a vendor module that depend on a different jQuery version, all these jQuery versions will be included in the generated vendor bundle.

To avoid this behaviour, you can add some logic to control which jQuery version(s) will be included, by using a webpack null-loader.

npm install null-loader --save-dev

Here we prevent others jQuery versions than the Foundation-sites's one to be included :

module: {
  ...
  loaders: [
    ...
    {
    test: /jquery\.js/,
    loader: 'null-loader',
    exclude: path.resolve('node_modules/foundation-sites/')
  }
}