# esm-config

> Transform es module configs to cjs using rollup.

Latest version **1.1.0** (published 2019-09-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install esm-config
pnpm add esm-config
yarn add esm-config
bun add esm-config
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2019-09-02 |
| First published | 2019-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 1 |
| Unpacked size | 3.9 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Lukas Ehnle |
| Maintainers | ocjojo |
| Keywords | esm config, rollup, transform esm |

## Links

- npm: https://www.npmjs.com/package/esm-config
- Repository: https://github.com/ocjojo/esm-config
- Homepage: https://github.com/ocjojo/esm-config#readme
- Issues: https://github.com/ocjojo/esm-config/issues
- npm.io page: https://npm.io/package/esm-config

## Dependencies (1)

- [rollup](https://npm.io/package/rollup.md) ^1.17.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2019-09-02
- 1.0.0 — 2019-07-28

## README

# ESM Config

Transform ES module configs to cjs using rollup.

## Why?

Since ES6 `import` and `export` are standard, yet there is still ~~no support~~ only experimental support in NodeJS.

Most of the time that is not a problem, since projects have a build step transforming (webpack/rollup/babel) the syntax. So people expect **import/export** to just work.

This module allows you to use ES modules syntax to write your configuration. Build a project or framework that allows more advanced configuration than toml, yaml or json would.
Like `rollup.config.js`, `webpack.config.js`, or `postcss.config.js`. (Only rollup allows import/export out of the box).

## Usage
Within your project let `esm-config` import your configuration file.

```js
const esmConfig = require("esm-config")

// /example/config.js may contain import/export syntax
const config = esmConfig("/example/config.js")

// you can provide a default configuration
// it is used, if the config file does not exist
// it is passed, if the config file exports a function
const defaultConfiguration = {
	name: "defaultName"
}
const config = esmConfig("/example/config.js", defaultConfiguration)
```

---

The configuration can then be written as either ESM or CJS module.

```js
// example ESM config
export default {
	name: "hello world"
}

// example exporting a function
// is passed the default configuration
export default function(defaultConfiguration) {
	const { name } = defaultConfiguration
	return {
		name,
		otherConfig: false
	}
}

// example CJS config
// this would work in nodejs without esm-config
module.exports = {
	name: "hello world"
}
```

## Background 
This uses a modified version of rollups internal [loadConfigFile](loadconfig) function.

Rollup configs can be written using ES modules syntax, because rollup transforms them to CJS before using them.

[loadconfig]: https://github.com/rollup/rollup/blob/def3ae2b4d2e5fde0f28d5ff1bf92ab9a2899e28/bin/src/run/loadConfigFile.ts

## License

MIT

---
_Source: https://npm.io/package/esm-config · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
