Skip to content

Commit

Permalink
Remove rewire helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
timarney committed Jan 6, 2019
1 parent eb19f55 commit 0848602
Showing 1 changed file with 0 additions and 56 deletions.
56 changes: 0 additions & 56 deletions packages/react-app-rewired/index.js
@@ -1,61 +1,5 @@
const path = require('path');
const paths = require('./scripts/utils/paths');

const loaderNameMatches = function(rule, loader_name) {
return rule && rule.loader && typeof rule.loader === 'string' &&
(rule.loader.indexOf(`${path.sep}${loader_name}${path.sep}`) !== -1 ||
rule.loader.indexOf(`@${loader_name}${path.sep}`) !== -1);
};

const babelLoaderMatcher = function(rule) {
return loaderNameMatches(rule, 'babel-loader');
};

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

rules.some(rule => {
return (loader = matcher(rule)
? rule
: getLoader(rule.use || rule.oneOf || (Array.isArray(rule.loader) && rule.loader) || [], 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;
}
// Older versions of webpack have `plugins` on `loader.query` instead of `loader.options`.
const options = loader.options || loader.query;
options.plugins = [pluginName].concat(options.plugins || []);
return config;
};

const compose = function(...funcs) {
if (funcs.length === 0) {
return config => config;
}

if (funcs.length === 1) {
return funcs[0];
}

return funcs.reduce((a, b) => (config, env) => a(b(config, env), env));
};

module.exports = {
getLoader,
loaderNameMatches,
getBabelLoader,
injectBabelPlugin,
compose,
paths
};

0 comments on commit 0848602

Please sign in to comment.