calacitizen
calacitizen

Reputation: 41

Configure webpack to ignore define statement

How can I confgure webpack to ignore amd 'define' statements in the file, like I can do it with 'require' with externals option?

Upvotes: 4

Views: 1379

Answers (2)

Hitmands
Hitmands

Reputation: 14179

as stated here: https://github.com/webpack/webpack/issues/3017#issuecomment-285954512

you could do:

module: {
  rules: [
    { parser: { amd: false } }
  ]
}

Upvotes: 1

ahz
ahz

Reputation: 950

Officially it is recommended to set define to false with imports-loader.

loaders: [
  { test: /\.js/, loader: 'imports?define=>false'}
]

But it is useful only if define is called in UMD style - something like this:

if (typeof define === 'function' && define.amd) {
  define([], factory)
}

If you can change code that calls define and there is no UMD's if this is what worked for me:

var define = window['infor']; // keep webpack out of way

// use define from global scope (requirejs or other used loader) as needed
define('mymodule', ['dep1'], function (dep1) {
  return {}
});

Upvotes: 0

Related Questions