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 should avoid dynamic require
calls, as these cannot be optimized.
This rule aims to prevent usage of dynamic require
calls.
The following patterns are considered warnings:
// AMD-Style Require
var paths = someCondition ? ['a', 'b'] : ['c', 'd'];
require(paths, function (a, b) {
/* ... */
});
require(['path/to/' + name], function (mod) {
/* ... */
});
// Simplified CommonJS Wrapped Require
define(function (require) {
var lib = require(someCondition ? 'a' : 'b');
/* ... */
});
define(function (require) {
var lib = require('path/to/' + name);
/* ... */
});
The following patterns are not warnings:
define(['path/to/a', 'path/to/b'], function (a, b) {
/* ... */
});
define(function (require) {
var a = require('path/to/a');
/* ... */
});
If you want to use dynamically-generated paths in a require
call, then it is safe to disable this rule.