1.0.2 • Published 4 years ago

export.macro v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

English | 简体中文

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,
});