const path = require('path');

const babelLoaderMatcher = function(rule) {
  return rule.loader && rule.loader.indexOf(`babel-loader${path.sep}`) != -1;
}

const getLoader = function(rules, matcher) {
  var loader;

  rules.some(rule => {
    return loader = matcher(rule)
      ? rule
      : getLoader(rule.use || rule.oneOf || [], matcher);
  });

  return loader;
};

const getBabelLoader = function(rules) {
  return getLoader(rules, babelLoaderMatcher);
}

const injectBabelPlugin = function(pluginName, config) {
  const loader = getBabelLoader(config.module.rules);
  if (!loader) {
    console.log("babel-loader not found");
    return config;
  }
  loader.options.plugins = [pluginName].concat(loader.options.plugins || []);
  return config;
};

module.exports = { getLoader, getBabelLoader, injectBabelPlugin };

@@ -652,23 +652,162 @@
 ;%0A  %7D%0A  
-loader.
+%0A  // Older versions of webpack have %60plugins%60 on %60loader.query%60 instead of %60loader.options%60.%0A  const options = loader.options %7C%7C loader.query;%0A  
 options.
@@ -836,23 +836,16 @@
 .concat(
-loader.
 options.

Make `injectBabelPlugin` compatible with older webpack versions