Skip to content

Commit

Permalink
Flatten rules after oneOf was added to create-react-app webpack configs
Browse files Browse the repository at this point in the history
  • Loading branch information
tb committed Oct 15, 2017
1 parent 2157950 commit 8c89cf5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 8c89cf5

Please sign in to comment.