Skip to content

Latest commit

 

History

History
51 lines (37 loc) · 1.29 KB

no-conditional-require.md

File metadata and controls

51 lines (37 loc) · 1.29 KB

Disallow use of conditional require calls (no-conditional-require)

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.

Rule Details

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');
    /* ... */
});

When Not To Use It

If you want to use conditionally loaded modules, then it is safe to disable this rule.

Further Reading