1.1.4 • Published 8 months ago

@rnx-kit/babel-plugin-import-path-remapper v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@rnx-kit/babel-plugin-import-path-remapper

Build npm version

@rnx-kit/babel-plugin-import-path-remapper remaps **/lib/** imports to **/src/**. This is useful for packages that are not correctly exporting everything via their index.ts, but you still want to consume the TypeScript files rather than the transpiled JavaScript.

Usage

Add @rnx-kit/babel-plugin-import-path-remapper to your babel.config.js under plugins. For example, to remap all paths under the @rnx-kit scope:

// babel.config.js
module.exports = {
  presets: ["module:metro-react-native-babel-preset"],
  overrides: [
    {
      test: /\.tsx?$/,
      plugins: [
        // @babel/plugin-transform-typescript doesn't support `const enum`s.
        // See https://babeljs.io/docs/en/babel-plugin-transform-typescript#caveats
        // for more details.
        "const-enum",

        [
          "@rnx-kit/babel-plugin-import-path-remapper",
          { test: (source) => source.startsWith("@rnx-kit/") },
        ],
      ],
    },
  ],
};

Or, if you're using @rnx-kit/metro-config:

// babel.config.js
const { makeBabelConfig } = require("@rnx-kit/metro-config");
module.exports = makeBabelConfig([
  [
    "@rnx-kit/babel-plugin-import-path-remapper",
    { test: (source) => source.startsWith("@rnx-kit/") },
  ],
]);

Options

OptionTypeDescription
test(source: string) => booleanRequired A function returning whether the passed source should be redirected to another module.
remap(moduleName: string, path: string) => stringOptional A function returning the module that should be used instead, e.g. contoso/index.js -> contoso/index.ts.
1.1.4

8 months ago

1.1.3

1 year ago

1.1.1

2 years ago

1.1.2

2 years ago

1.1.0

2 years ago

1.0.11

2 years ago

1.0.12

2 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago