Skip to content

Commit

Permalink
Merge pull request #223 from alexasselin008/feature/craco_configurati…
Browse files Browse the repository at this point in the history
…on_file#213

Add support for .cracorc and .cracorc.js
  • Loading branch information
patricklafrance authored Dec 7, 2020
2 parents d51d5d7 + 20b4119 commit 161aee8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/craco/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ $ npm run build

## Configuration

CRACO is configured with the `craco.config.js` file. This file is divided into sections representing the major parts of what makes up the default create react app.
CRACO is configured with a `craco.config.js`, `.cracorc.js` or `.cracorc` file. This file is divided into sections representing the major parts of what makes up the default create react app.

If there are multiple configuration files in the same directory, CRACO will only use one. The priority order is:

1. `craco.config.js`
2. `.cracorc.js`
3. `.cracorc`

### Configuration File

Expand Down
11 changes: 10 additions & 1 deletion packages/craco/lib/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ log("Project root path resolved to: ", projectRoot);

let configFilePath = "";

const configFilenames = ["craco.config.js", ".cracorc.js", ".cracorc"];

const args = getArgs();

if (args.config.isProvided) {
Expand All @@ -25,7 +27,14 @@ if (args.config.isProvided) {

configFilePath = path.resolve(projectRoot, package.cracoConfig);
} else {
configFilePath = path.resolve(projectRoot, "craco.config.js");
for (const filename of configFilenames) {
const filePath = path.join(projectRoot, filename);

if (fs.existsSync(filePath)) {
configFilePath = filePath;
break;
}
}
}
}

Expand Down

0 comments on commit 161aee8

Please sign in to comment.