Skip to content

RFC: Support babel.config.json for better cacheability #10495

@devongovett

Description

@devongovett

At the moment, Babel supports several configuration options: .babelrc, .babelrc.js, and babel.config.js. Many projects have migrated to babel.config.js since it was introduced, especially monorepos. However, many configs are still quite simple and could be JSON instead of JavaScript. This has several benefits, including better cacheability. Babel should support babel.config.json in addition to its existing options for those cases.

Using JavaScript for configs can be nice when you need to do complex condition-based configuration, but it has several downsides including preventing caching. In Parcel 2, we have to bail on caching all files compiled with Babel when a JavaScript config file is used instead of JSON. Unfortunately, that leaves no recourse to users if they want the benefits of caching, but want to use a root config. If Babel supported babel.config.json, these issues would be alleviated somewhat. For simple configs that are JSON serializable, Parcel and other tools could correctly cache files as is already possible with .babelrc.

I am aware of the Babel config caching API, but it's not really designed for use in a cache that is serialized to disk. It is designed to avoid re-calling the config function, not to avoid re-compiling files. In addition, the API relies on callback functions to determine if the cache should be invalidated, but that only works when the callback can be stored in memory - we cannot serialize it to disk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has PRoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions