From 8c89cf54479f56ba15ba154feec24c309ea80f2f Mon Sep 17 00:00:00 2001 From: tb Date: Sun, 15 Oct 2017 06:44:05 +0200 Subject: [PATCH] Flatten rules after oneOf was added to create-react-app webpack configs see https://github.com/facebookincubator/create-react-app/pull/2747 --- index.js | 9 +++++++-- package.json | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 1cf9283..d7b68d7 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,13 @@ function rewireGraphQLTag(config, env) { const gqlExtension = /\.(graphql|gql)$/ - const fileLoader = config.module.rules.find(rule=> rule.loader && rule.loader.indexOf("file-loader")!==-1); - fileLoader.exclude.push(gqlExtension); + const flatten = (array) => array.reduce((a, b) => + a.concat(Array.isArray(b) ? flatten(b) : b), []); + + const fileLoader = flatten(config.module.rules.map((rule) => rule.oneOf || rule)) + .find((rule) => rule.loader && rule.loader.indexOf("file-loader")!==-1); + + fileLoader && fileLoader.exclude.push(gqlExtension); const gqlTagRule = { test: gqlExtension, diff --git a/package.json b/package.json index 2d4b7ad..ab1acdd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-app-rewire-graphql-tag", - "version": "1.0.0", + "version": "1.1.0", "description": "rewire your react-app and use graphql-tag", "main": "index.js", "scripts": {