Skip to content

Commit

Permalink
mention ESM loading
Browse files Browse the repository at this point in the history
  • Loading branch information
antonk52 committed Feb 13, 2024
1 parent fd2a5bd commit 41aa538
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ lilconfigSync(
*/
```

## ESM

ESM configs can be loaded with **async API only**. Specifically `js` files in projects with `"type": "module"` in `package.json` or `mjs` files.

## Difference to `cosmiconfig`
Lilconfig does not intend to be 100% compatible with `cosmiconfig` but tries to mimic it where possible. The key difference is **no** support for yaml files out of the box(`lilconfig` attempts to parse files with no extension as JSON instead of YAML). You can still add the support for YAML files by providing a loader, see an [example](#yaml-loader) below.

Expand Down Expand Up @@ -87,29 +91,6 @@ lilconfig('myapp', options)
});
```

### ESM loader

Lilconfig v2 does not support ESM modules out of the box. However, you can support it with a custom a loader. Note that this will only work with the async `lilconfig` function and won't work with the sync `lilconfigSync`.

```js
import {lilconfig} from 'lilconfig';

const loadEsm = filepath => import(filepath);

lilconfig('myapp', {
loaders: {
'.js': loadEsm,
'.mjs': loadEsm,
}
})
.search()
.then(result => {
result // {config, filepath}

result.config.default // if config uses `export default`
});
```

## Version correlation

- lilconig v1 → cosmiconfig v6
Expand Down

0 comments on commit 41aa538

Please sign in to comment.