export.macro

export all from current path(all files and all dirs)

Usage no npm install needed!

<script type="module">
  import exportMacro from 'https://cdn.skypack.dev/export.macro';
</script>

README

English | 简体中文

export.macro

export all from current path

NPM version Build Status codecov

install

npm i -D export.macro
// or
yarn add -D export.macro

ensure you have installed babel-plugin-macros

.babelrc

{
  plugins: ['babel-plugin-macros']
}

usage

import exportAll from "export.macro";

exportAll("./", {
  exclude: ["**/*.test.js"],
  noDefault: false,
  onlyIndex: true,
});

output:

export {default as Something} from "./Something";
export * from "./Something";
...

custom import

add a config file:

  • .babel-plugin-macrosrc
  • .babel-plugin-macrosrc.json
  • .babel-plugin-macrosrc.yaml
  • .babel-plugin-macrosrc.yml
  • .babel-plugin-macrosrc.js
  • babel-plugin-macros.config.js
  • babelMacros in package.json

Configuration is as follows:

options

  • exclude string[]: glob ignore config, alreday add node_modules/**/*
  • noDefault boolean: make sure don't need export {default as Filename} from './Filename', default is false
  • onlyIndex boolean: for dir, just export index file, default is true
// .babel-plugin-macrosrc.js
module.exports = {
  exportAllHelper: {
    exclude: ["node_modules/**/*"],
    noDefault: false,
    onlyIndex: true,
  },
};

then, you can import customImport from export.macro

import exportAll from "export.macro";
exportAll("filename", {
  exclude: ["node_modules/**/*"],
  noDefault: false,
  onlyIndex: true,
});