If you are using r.js to create an optimized build of your project, or using a third-party module loader such as Almond, you may wish to avoid conditional loading of dependencies, as it might not be possible to optimize these.
This rule aims to prevent usage of require
inside of a conditional statement or expression.
The following patterns are considered warnings:
if (someCondition) {
require(['a', 'b'], function (a, b) {
/* ... */
});
}
define(function (require) {
if (someCondition) {
var lib = require('lib');
/* ... */
}
});
define(function (require) {
var lib = someCondition ? require('a') : require('b');
/* ... */
});
The following patterns are not warnings:
define(['a', 'b'], function (a, b) {
/* ... */
});
define(function (require) {
var a = require('a');
/* ... */
});
If you want to use conditionally loaded modules, then it is safe to disable this rule.