src/convertRuleToCondition.js
function convertRuleToCondition(rule) {
    if (!rule || typeof rule !== 'object' || !Object.keys(rule).length) {
        return rule;
    }
    if (Array.isArray(rule)) {
        return rule.map(convertRuleToCondition);
    }
    const condition = {};
    // We allow certain properties...
    ALLOWED_PROPERTIES.forEach((prop) => {
        if (rule[prop]) {
            condition[prop] = convertRuleToCondition(rule[prop]);
        }
    });
    // We prohibit certain properties...
    PROHIBITIED_PROPERTIES.forEach((prop) => {
        if (rule[prop]) {
            throw new Error(`Webpack rules added in a Twist library cannot contain the property "${prop}". `
                + `Try to reformulate your rule with ${ALLOWED_PROPERTIES.join('/')}.`);
        }
    });
    // And the rest we ignore, because they're needed for a Rule but not a Condition.
    return condition;
}
function convertRuleToCondition(rule) {
    if (!rule || typeof rule !== 'object' || !Object.keys(rule).length) {
        return rule;
    }
    if (Array.isArray(rule)) {
        return rule.map(convertRuleToCondition);
    }
    const condition = {};
    // We allow certain properties...
    ALLOWED_PROPERTIES.forEach((prop) => {
        if (rule[prop]) {
            condition[prop] = convertRuleToCondition(rule[prop]);
        }
    });
    // We prohibit certain properties...
    PROHIBITIED_PROPERTIES.forEach((prop) => {
        if (rule[prop]) {
            throw new Error(`Webpack rules added in a Twist library cannot contain the property "${prop}". `
                + `Try to reformulate your rule with ${ALLOWED_PROPERTIES.join('/')}.`);
        }
    });
    // And the rest we ignore, because they're needed for a Rule but not a Condition.
    return condition;
}
function convertRuleToCondition ( rule ) { if ( ! rule || typeof rule !== 'object' || ! Object . keys ( rule ) . length ) { return rule ; } if ( Array . isArray ( rule ) ) { return rule . map ( convertRuleToCondition ) ; } const condition = { } ; // We allow certain properties... ALLOWED_PROPERTIES . forEach ( ( prop ) => { if ( rule [ prop ] ) { condition [ prop ] = convertRuleToCondition ( rule [ prop ] ) ; } } ) ; // We prohibit certain properties... PROHIBITIED_PROPERTIES . forEach ( ( prop ) => { if ( rule [ prop ] ) { throw new Error ( ` ${ prop } ` + ` ${ ALLOWED_PROPERTIES . join ( '/' ) } ` ) ; } } ) ; // And the rest we ignore, because they're needed for a Rule but not a Condition. return condition ; }
Create a Webpack Condition from a Webpack Rule by stripping out any nested Rule properties,
keeping only the conditions in which the rule would be applied. In other words, the return
value of this function could be passed to `exclude` on another rule, to exclude only the
files matched by the input rule.

@param {Rule} rule
@return {Condition}
Create a Webpack Condition from a Webpack Rule by stripping out any nested Rule properties keeping only the conditions in which the rule would be applied . In other words the return value of this function could be passed to exclude on another rule to exclude only the files matched by the input rule .