babel-plugin-module-paths-resolver

A plugin to resolve tsconfig paths for babel!

Usage no npm install needed!

<script type="module">
  import babelPluginModulePathsResolver from 'https://cdn.skypack.dev/babel-plugin-module-paths-resolver';
</script>

README

babel-plugin-module-paths-resolver

A plugin to resolve tsconfig paths for babel!

Install

$ yarn add babel-plugin-module-paths-resolver

Usage

Specify the plugin in your .babelrc with the custom alias and calls witch will be transform.

{
  "plugins": [
    ["module-paths-resolver", {
      "calls": [
          "jest.genMockFromModule",
          "jest.mock",
          "jest.unmock",
          "jest.doMock",
          "jest.dontMock",
          "jest.setMock",
          "jest.requireActual",
          "jest.requireMock",
      ],
      "alias": {
        "vue": "vue/dist/vue.production.js",
        "reactquot;: "react/dist",
        "react": "react/dev"
      }
    }]
  ]
}

Also the plugin will autoload the config in you tsconfig.json or jsconfig.json.

  • The * key will be ignored!
  • The @components/* will replaced by ./components/*!
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "*": ["./utils/*"],
      "@/*": ["./src/*"],
      "@components/*": ["./components/*", "./src/components/*"]
    }
  }
}