This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

babel-plugin-custom-import-path-transform

1.0.3 • Public • Published

babel-plugin-custom-import-path-transform

A babel plugin to rewrite module imports (and require) using a custom function.

Description

You can supply a replace function to dynamically replace module paths when Babel traverses them.

Usage

Install the plugin:

$ yarn add -D babel-plugin-custom-import-path-transform

Specify the plugin in your .babelrc with the file that exports the replace function.

{
    "plugins": [
        [
            "babel-plugin-custom-import-path-transform",
            {
                "transformImportPath": "./scripts/transformImportPath.js"
            }
        ]
    ]
}

Let's say you want ~/moduleFile to be replaced to utils/moduleFile if the calling file is in utils, and common/moduleFile otherwise. So in your replace-module-paths.js, just export:

function transformImportPath(originalPath, callingFileName, options) {
    if (callingFileName.indexOf('/utils/') !== -1) {
        return originalPath.replace('~', 'utils');
    } else {
        return originalPath.replace('~', 'common');
    }
}
 
module.exports = transformImportPath;

License

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Published

Version History

VersionDownloads (Last 7 Days)Published

Package Sidebar

Install

npm i babel-plugin-custom-import-path-transform

Weekly Downloads

10

Version

1.0.3

License

MIT

Unpacked Size

6.58 kB

Total Files

6

Last publish

Collaborators

  • ackeecz