Skip to content

Commit

Permalink
Add support for vocab.config.cjs (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
rstacruz committed Nov 12, 2023
1 parent f814929 commit 8228608
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-lamps-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vocab/core": minor
---

Add support for a alternative config file name, `vocab.config.cjs`
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $ npm i --save @vocab/core @vocab/react

### Step 2: Configure Vocab

You can configure Vocab directly when calling the API or via a `vocab.config.js` file.
You can configure Vocab directly when calling the API or via a `vocab.config.js` or `vocab.config.cjs` file.

In this example we've configured two languages, English and French, where our initial `translation.json` files will use English.

Expand Down Expand Up @@ -184,7 +184,7 @@ t('my key with component', {

## Configuration

Configuration can either be passed into the Node API directly or be gathered from the nearest _vocab.config.js_ file.
Configuration can either be passed into the Node API directly or be gathered from the nearest _vocab.config.js_ or _vocab.config.cjs_ file.

**vocab.config.js**

Expand Down Expand Up @@ -341,7 +341,7 @@ functionality.

### Generating a pseudo-localized language using Vocab

Vocab can generate a pseudo-localized language via the [`generatedLanguages` config][generated languages config], either via the webpack plugin or your `vocab.config.js` file.
Vocab can generate a pseudo-localized language via the [`generatedLanguages` config][generated languages config], either via the webpack plugin or your `vocab.config.js` or `vocab.config.cjs` file.
`@vocab/pseudo-localize` exports a `generator` that can be used directly in your config.

**vocab.config.js**
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export async function resolveConfig(
): Promise<UserConfig | null> {
const configFilePath = customConfigFilePath
? path.resolve(customConfigFilePath)
: await findUp('vocab.config.js');
: await findUp(['vocab.config.js', 'vocab.config.cjs']);

if (configFilePath) {
trace(`Resolved configuration file to ${configFilePath}`);
Expand All @@ -192,7 +192,7 @@ export function resolveConfigSync(
): UserConfig | null {
const configFilePath = customConfigFilePath
? path.resolve(customConfigFilePath)
: findUp.sync('vocab.config.js');
: findUp.sync(['vocab.config.js', 'vocab.config.cjs']);

if (configFilePath) {
trace(`Resolved configuration file to ${configFilePath}`);
Expand Down

0 comments on commit 8228608

Please sign in to comment.