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
!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 aglob
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 supportsexport
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'sdevDependencies
:npm install --save-dev export-all.macro
Usage
Once you've configuredbabel-plugin-macros
you can
import/require export-all.macro
.The
exportAll
functions accept a glob
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 exportsimport 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 (likeeslint-plugin-import
) will probably fail on this.Inspiration
Sunil Pai's tweetsunil-tweetOther 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 💻 📖 ⚠️ 🔧 💡 📓 |
This project follows the all-contributorsall-contributors specification. Contributions of any kind welcome!