0.1.5 • Published 3 years ago

babel-plugin-replace-exports v0.1.5

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

babel-plugin-replace-exports

Babel plugin for replace all exports with dynamic values.

Input:

// server/serverApi.js
export function someServerApi(params) {
  // server side logic...
}

Output:

import { createAjaxApi as _factory } from '@/lib/createAjaxApi'
var _filename = 'server/serverApi.js'
export var someServerApi = /*#__PURE__*/_factory(_filename, 'someServerApi')

Plugin will remove anything except re-exports.

Options

factory

required, string.

Factory module name.

Example:

// { factory: 'foo' }
import { default as _factory } from 'foo';

basepath

string, defaults to cwd.

Specify basepath for resolving file name.

includes

Array<string>, defaults to null.

If specified, plugin will only transpile specific files. It uses micromatch for matching file names.

factoryImportName

string, defaults to 'default'.

Import name of the factory function.

Example:

// { factoryImportName: 'myCustomImport' }
import { myCustomImport as _factory } from '@/lib/createAjaxApi';

mapFilename

function, defaults to v => v.

Transform filename passed to the factory.

Example:

// { mapFilename: (filename, state) => filename.replace(/\.js$/, '') }
var _filename = 'server/serverApi'