imports loader module for webpack
Can be used to inject variables into the scope of a module. This is especially useful if third-party modules are relying on global variables like
this being the
npm install imports-loader
Given you have this file
then you can inject the
$ variable into the module by configuring the imports-loader like this:
This simply prepends
var $ = require("jquery"); to
Multiple values are separated by comma
As always, you should rather configure this in your
// ./webpack.config.jsmoduleexports =module:loaders:test: requireresolve"some-module"loader: "imports?this=>window";
There are many modules that check for a
define function before using CommonJS. Since webpack is capable of both, they default to AMD in this case, which can be a problem if the implementation is quirky.
Then you can easily disable the AMD path by writing
For further hints on compatibility issues, check out Shimming Modules of the official docs.