From 291a771bd9a5eeb2284efc19b6fc349dd4d09919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Mon, 21 Aug 2017 16:52:28 +0100 Subject: [PATCH] fix(cp-frontend): fix react-scripts patch --- .../scripts/patch-webpack-config.js | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/packages/cp-frontend/scripts/patch-webpack-config.js b/packages/cp-frontend/scripts/patch-webpack-config.js index 176732f1..fd350a6f 100644 --- a/packages/cp-frontend/scripts/patch-webpack-config.js +++ b/packages/cp-frontend/scripts/patch-webpack-config.js @@ -6,6 +6,22 @@ const path = require('path'); const FRONTEND_ROOT = process.cwd(); const FRONTEND = path.join(FRONTEND_ROOT, 'src'); +const BabelLoader = loader => ({ + test: loader.test, + include: loader.include, + loader: loader.loader, + options: { + babelrc: true, + cacheDirectory: true + } +}); + +const FileLoader = loader => ({ + exclude: loader.exclude.concat([/\.(graphql|gql)$/]), + loader: loader.loader, + options: loader.options +}); + module.exports = config => { config.resolve.plugins = []; @@ -38,32 +54,36 @@ module.exports = config => { ]); } + if (Array.isArray(loader.oneOf)) { + return Object.assign(loader, { + oneOf: loader.oneOf.map(loader => { + if (!isString(loader.loader)) { + return loader; + } + + if (loader.loader.match(/babel-loader/)) { + return BabelLoader(loader); + } + + if (loader.loader.match(/file-loader/)) { + return FileLoader(loader); + } + + return loader; + }) + }); + } + if (!isString(loader.loader)) { - return loaders.concat([loader]); + return loader; } if (loader.loader.match(/babel-loader/)) { - return loaders.concat([ - { - test: loader.test, - include: loader.include, - loader: loader.loader, - options: { - babelrc: true, - cacheDirectory: true - } - } - ]); + return loaders.concat(BabelLoader(loader)); } if (loader.loader.match(/file-loader/)) { - return loaders.concat([ - { - exclude: loader.exclude.concat([/\.(graphql|gql)$/]), - loader: loader.loader, - options: loader.options - } - ]); + return loaders.concat([FileLoader(loader)]); } return loaders.concat([loader]);