0.0.0 • Published 5 years ago

export-all.macro v0.0.0

Weekly downloads
36
License
MIT
Repository
github
Last release
5 years ago

Build Status Code Coverage version downloads MIT License

All Contributors PRs Welcome Code of Conduct Babel Macro

Watch on GitHub Star on GitHub Tweet

The problem

You want to export all files that match a glob without having to export them individually.

This solution

This is a babel-plugin-macro which allows you to export files that match a glob. It supports export statements for synchronous resolution.

Table of Contents

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies:

npm install --save-dev export-all.macro

Usage

Once you've configured babel-plugin-macros you can import/require export-all.macro.

The exportAll functions accept a glob and will transpile your code to export statements for each file that matches the given glob.

Let's imagine you have a directory called my-files with the files a.js, b.js, c.js, and d.js.

Here are a few before/after examples:

exportAll uses static exports: README:1 exportAll uses static exports

import exportAll from 'export-all.macro'

exportAll('./files/*.js')

      ↓ ↓ ↓ ↓ ↓ ↓

export * from './files/a.js'
export * from './files/b.js'
export * from './files/c.js'
export * from './files/d.js'

Caveats

Some static analysis tools (like ESLint, Flow, and Jest) wont like this very much without a little additional work. So Jest's watch mode may not pick up all your tests that are relevant based on changes and some ESLint plugins (like eslint-plugin-import) will probably fail on this.

Inspiration

Sunil Pai's tweet

Other Solutions

I'm not aware of any, if you are please make a pull request and add it here!

Contributors

Thanks goes to these people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT