Expose Jquery to Real Window Object with Webpack

Expose jQuery to real Window object with Webpack

You need to use the expose-loader.

npm install expose-loader --save-dev

You can either do this when you require it:

require("expose?$!jquery");

or you can do this in your config:

loaders: [
{ test: require.resolve('jquery'), loader: 'expose?jQuery!expose?$' }
]

UPDATE: As of webpack 2, you need to use expose-loader instead of expose:

module: {
rules: [{
test: require.resolve('jquery'),
use: [{
loader: 'expose-loader',
options: '$'
}]
}]
}

Expose multiple different objects on the window with webpack

According to this section of the doc, what you want to achieve is doable by ensuring:

  1. You module is the entry point
  2. output.library is falsy
  3. output.libraryTarget = "window"


Related Topics



Leave a reply



Submit