export-all.macro

A macro for babel-plugin-macros that allows you to export all files that match a glob

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
export-all.macro
0.0.05 years ago5 years agoMinified + gzip package size for export-all.macro in KB

Readme

export-all.macro

A babel-plugin-macro that allows you to export all files that match a glob




!Build Statusbuild-badgebuild !Code Coveragecoverage-badgecoverage !versionversion-badgepackage !downloadsdownloads-badgenpmtrends !MIT Licenselicense-badgelicense
All Contributors !PRs Welcomeprs-badgeprs !Code of Conductcoc-badgecoc !Babel Macromacros-badgebabel-plugin-macros
!Watch on GitHubgithub-watch-badgegithub-watch !Star on GitHubgithub-star-badgegithub-star !Tweettwitter-badgetwitter

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-macrobabel-plugin-macros 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 npmnpm which is bundled with nodenode 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 globglob 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 tweetsunil-tweet

Other Solutions

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

Contributors

Thanks goes to these people (emoji keyemojis):
Aaron Reisman
Aaron Reisman

💻 📖 ⚠️ 🔧 💡 📓


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

LICENSE

MIT