Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to disable AMDPlugin?

Tags:

webpack

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?

like image 617
Wiktor Kozlik Avatar asked Mar 27 '15 14:03

Wiktor Kozlik


3 Answers

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'} ]
like image 58
kucherenkovova Avatar answered Oct 24 '22 06:10

kucherenkovova


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/

like image 36
Matt B Avatar answered Oct 24 '22 05:10

Matt B


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.

like image 1
Darren Shewry Avatar answered Oct 24 '22 07:10

Darren Shewry