browserslist-load-config
Introduction
This package is a fork of browserslist.loadConfig with some modifications to make it faster.
Compare to browserslist
, this package has the following improvements and differences:
- 27 times smaller bundle size
- 140 times smaller install size.
- Zero dependencies.
- Written in TypeScript.
- Smaller and faster.
- Does not support env variables.
See bundlephobia - browserslist-load-config vs bundlephobia - browserslist for bundle size comparison.
See packagephobia - browserslist-load-config vs packagephobia - browserslist for install size comparison.
Credits
Thanks Andrey Sitnik for creating the Browserslist which is under MIT License.
Usage
Install:
npm add browserslist-load-config -D
loadConfig
Loads the browserslist configuration from the specified file or directory, returns the browserslist config of specified environment.
- Type:
type LoadConfigOptions = {
/**
* Specify the path to the configuration file
* If both `config` and `path` are provided, `config` will be used
*/
config?: string;
/**
* Specify the directory where the configuration file is located
*/
path?: string;
/**
* Specify the environment to load
* @default "production"
*/
env?: string;
};
function loadConfig(opts: LoadConfigOptions): string[] | undefined;
- Example:
import { loadConfig } from "browserslist-load-config";
// Pass a path to the configuration file
const config = loadConfig({
path: "./path/to/project/root",
env: "production",
});
// Pass a browserslist config directly
const config = loadConfig({
config: "./path/to/project/root/.browserslistrc",
env: "production",
});
console.log(config);
/**
* [
* // browserslist config
* ]
*/
findConfig
Finds the browserslist configuration file in the specified directory, returns the resolved browserslist config object.
- Type:
function findConfig(from: string): Record<string, string[]> | undefined;
- Example:
import { findConfig } from "browserslist-load-config";
const config = findConfig("./path/to/project/root");
console.log(config);
/**
* {
* defaults: [
* // default browserslist config
* ],
* development: [
* // development browserslist config
* ],
* production: [
* // production browserslist config
* ],
* }
*/
License
MIT.