Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

find-babel-config

tleunen11.3mMIT2.1.2

Find the closest babel config based on a directory

babel, config, loader, finder, babelrc

readme

find-babel-config

npm Build Status Coverage Status

Helper function to retrieve the closest Babel configuration from a specific directory.

Installation

npm install --save find-babel-config

Usage

Async

// 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);
    }
});

Sync

// 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 file === null, the config wasn't found. (Also config === null)
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).

License

MIT, see LICENSE.md for details.

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.1.2 (2024-09-02)

Bug Fixes

2.1.1 (2024-04-17)

Bug Fixes

2.1.0 (2024-04-17)

2.0.0 (2023-01-09)

⚠ BREAKING CHANGES

  • The order of config file lookup is ".babelrc, .babelrc.js, babel.config.js, babel.config.json, package.json"
  • Node 16 is the minimum supported version

Bug Fixes

  • Fix order of config file lookup to be the same in sync and async functions (#38) (4fde4bb)

1.2.0 (2019-03-04)

Features

1.1.0 (2017-05-08)

Features

1.0.1 (2016-08-20)

Bug Fixes

  • Fix async call with depth 0 (ddb684f)

1.0.0 (2016-08-06)

Features

  • Add support for async lookup (ca2f592)

BREAKING CHANGES

  • The default function is now async and uses a Promise. And the function doesn't return null when the config is not found. Instead, an object { file: null, config: null } is returned.

0.1.1 (2016-07-10)

Bug Fixes

  • release: Ignore src/ but not lib/ for npm (2588adf)

0.1.0 (2016-07-10)

Features

  • find: Initial commit with the find babel config function (cd861f4)