Webpack includes AMDPlugin by default, so if a module checks for AMD before CommonJS, that module definition will be used.
if (typeof define === 'function' && define.amd) {
define([], factory)
} else if (typeof exports === 'object') {
exports.foo = factory();
}
I would like to ignore AMD altogether. Is there a way to do it in webpack?
It can be solved with imports-loader
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
imports?define=>false
Simply do
require('imports?define=>false!myjsfile.js')
OR a better approach is in webpack.config.js you add a loader
loaders: [ { test: /myjsfile.js/, loader: 'imports?define=>false'} ]
You can also add to the following to your rules to disable AMD(webpack 2+):
module: {
rules: [
{ parser: { amd: false } }
]
}
From: https://webpack.js.org/configuration/module/
Also consider script-loader
, as mentioned at the end of the Shimming documentation:
The script-loader evaluates code in the global context, similar to inclusion via a script tag. In this mode, every normal library should work. require, module, etc. are undefined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With