babel-plugin-replace-exports
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

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'

Readme

Keywords

none

Package Sidebar

Install

npm i babel-plugin-replace-exports

Weekly Downloads

14

Version

0.1.5

License

MIT

Unpacked Size

16.8 kB

Total Files

15

Last publish

Collaborators

  • gzzhanghao