Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

babel-plugin-module-replace

AlexanderOMara42MPL-2.01.0.1

A Babel plugin to replace module import and export paths

babel, esm, es6, modules, resolve, resolver, import, export

readme

Babel Plugin: Module Replace

A Babel plugin for replacing import and export paths

npm node

size downloads

main

Overview

Replace ESM import and export paths by regular expression or JavaScript function.

Since it replaces the paths before the modules are transpiled, it can also be used to replace the paths for other transpiled module loaders.

Must be configured to change anything, it will not do anything by default.

Usage

Option: replace

Regular expression string pair

{
    "plugins": [
        [
            "module-replace",
            {
                "replace": [
                    ["/^alpha$/", "$1-new"],
                    ["/^beta$/", "$1-new"]
                ]
            }
        ]
    ]
}

Regular expression object pair (requires JS config file)

export default {
    plugins: [
        [
            'module-replace',
            {
                replace: [[/^(\.\.?\/.+)\.(m|c)?tsx?$/i, '$1.js']]
            }
        ]
    ]
};

Replace function (requires JS config file)

export default {
    plugins: [
        [
            'module-replace',
            {
                replace: [m => m.toLowerCase()]
            }
        ]
    ]
};

Bugs

If you find a bug or have compatibility issues, please open a ticket under issues section for this repository.

License

Copyright (c) 2024 Alexander O'Mara

Licensed under the Mozilla Public License, v. 2.0.

If this license does not work for you, feel free to contact me.