Transform es module configs to cjs using rollup.
Last updated a year ago by ocjojo .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install esm-config 
SYNC missed versions from official npm registry.

ESM Config

Transform ES module configs to cjs using rollup.


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).


Within your project let esm-config import your configuration file.

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.

// 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 {
		otherConfig: false

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


This uses a modified version of rollups internal loadConfigFile function.

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



Current Tags

  • 1.1.0                                ...           latest (a year ago)

2 Versions

  • 1.1.0                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (4)

Copyright 2014 - 2016 © |