orionsoft-react-scripts
Version:
Orionsoft Configuration and scripts for Create React App.
58 lines (45 loc) • 1.9 kB
Markdown
from a specific directory.
```sh
npm install --save find-babel-config
```
```js
// directory can be an absolute or relative path
// If it's a relative path, it is relative to the current working directory (process.cwd())
const directory = 'src';
findBabelConfig(directory).then(({ file, config }) => {
if (file) {
// file is the file in which the config is found
console.log(file);
// config is a JS plain object with the babel config
console.log(config);
}
});
```
```js
// directory can be an absolute or relative path
// If it's a relative path, it is relative to the current working directory (process.cwd())
const directory = 'src';
const { file, config } = findBabelConfig.sync(directory);
// if c === null, the config wasn't found
if (file) {
// file is the file in which the config is found
console.log(file);
// config is a JS plain object with the babel config
console.log(config);
}
```
A second parameter can be given to `findBabelConfig`, it specifies the `depth` of search. By default, this value is `Infinity` but you can set the value you want: `findBabelConfig('src', 10)`.
MIT, see [LICENSE.md](/LICENSE.md) for details.
[ ]: https://circleci.com/gh/tleunen/find-babel-config.svg?style=shield
[ ]: https://circleci.com/gh/tleunen/find-babel-config
[ ]: https://codecov.io/gh/tleunen/find-babel-config/branch/master/graph/badge.svg
[ ]: https://codecov.io/gh/tleunen/find-babel-config
[ ]: https://img.shields.io/npm/v/find-babel-config.svg
[ ]: https://www.npmjs.com/package/find-babel-config
[![npm][npm-version-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coverage Status][coverage-image]][coverage-url]
Helper function to retrieve the closest Babel configuration