{"id":16403542,"url":"https://github.com/ricokahler/babel-plugin-tsconfig-paths-module-resolver","last_synced_at":"2025-04-04T09:08:59.249Z","repository":{"id":39382632,"uuid":"401182124","full_name":"ricokahler/babel-plugin-tsconfig-paths-module-resolver","owner":"ricokahler","description":"Use tsconfig-paths in any bundler that supports a custom babel config.","archived":false,"fork":false,"pushed_at":"2025-03-24T19:35:28.000Z","size":873,"stargazers_count":40,"open_issues_count":12,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T08:08:09.073Z","etag":null,"topics":["babel","babel-plugin","babel-plugin-module-resolver","tsconfig","tsconfig-paths"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ricokahler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-30T01:31:26.000Z","updated_at":"2025-03-01T02:36:30.000Z","dependencies_parsed_at":"2023-02-17T02:20:25.380Z","dependency_job_id":"41cdfb48-bff1-44ef-9889-72729d7e72a5","html_url":"https://github.com/ricokahler/babel-plugin-tsconfig-paths-module-resolver","commit_stats":{"total_commits":28,"total_committers":4,"mean_commits":7.0,"dds":0.5357142857142857,"last_synced_commit":"e3917d973af146a3629ce2b18b2d428e93fa2184"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricokahler%2Fbabel-plugin-tsconfig-paths-module-resolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricokahler%2Fbabel-plugin-tsconfig-paths-module-resolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricokahler%2Fbabel-plugin-tsconfig-paths-module-resolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricokahler%2Fbabel-plugin-tsconfig-paths-module-resolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ricokahler","download_url":"https://codeload.github.com/ricokahler/babel-plugin-tsconfig-paths-module-resolver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247149501,"owners_count":20891954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["babel","babel-plugin","babel-plugin-module-resolver","tsconfig","tsconfig-paths"],"created_at":"2024-10-11T05:49:42.018Z","updated_at":"2025-04-04T09:08:59.229Z","avatar_url":"https://github.com/ricokahler.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# babel-plugin-tsconfig-paths-module-resolver\n\n[![npm](https://badgen.net/npm/v/babel-plugin-tsconfig-paths-module-resolver)](https://www.npmjs.com/package/babel-plugin-tsconfig-paths-module-resolver) [![Github Actions](https://badgen.net/github/checks/ricokahler/babel-plugin-tsconfig-paths-module-resolver)](https://github.com/ricokahler/babel-plugin-tsconfig-paths-module-resolver/actions) [![codecov](https://codecov.io/gh/ricokahler/babel-plugin-tsconfig-paths-module-resolver/branch/main/graph/badge.svg?token=2cQuXwu8Gq)](https://codecov.io/gh/ricokahler/babel-plugin-tsconfig-paths-module-resolver) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\n\u003e Combines [`babel-plugin-module-resolver`][0] and [`tsconfig-paths`][1] to make a babel plugin that resolves [tsconfig paths][2].\n\u003e\n\u003e Use tsconfig-paths in any bundler that supports a custom babel config.\n\nThis library is a re-export of [`babel-plugin-module-resolver`](https://github.com/tleunen/babel-plugin-module-resolver) pre-configured with [tsconfig paths][2] support via the package [`tsconfig-paths`][1].\n\nIt aims to be stable by relying on these already widely-used packages to power the heavy logic:\n\n| dependency                          | weekly downloads                                         |\n| ----------------------------------- | -------------------------------------------------------- |\n| [`babel-plugin-module-resolver`][0] | [![babel plugin module resolver weekly downloads][3]][4] |\n| [`tsconfig-paths`][1]               | [![tsconfig-paths weekly downloads][5]][6]               |\n\nThese dependencies are automatically updated via [renovate bot](https://github.com/renovatebot/renovate) and [semantic release](https://github.com/semantic-release/semantic-release).\n\n---\n\n**How is this different from [`babel-plugin-tsconfig-paths`](https://github.com/Js-Brecht/babel-plugin-tsconfig-paths)?**\n\n1. It does less — as stated above, this library depends on battled tested libs ([`tsconfig-paths`][1] and [`babel-plugin-module-resolver`][0]) to do the actual logic. The source code for this library is around ~100 SLOC which makes it easy to test and maintain.\n2. It re-exports [`babel-plugin-module-resolver`][0] — giving you all the features of that babel plugin including [custom resolve functions](#resolvepath-and-createresolvepath).\n\n---\n\n## Installation\n\n```\nnpm install --save-dev babel-plugin-tsconfig-paths-module-resolver\n```\n\nor\n\n```\nyarn add --dev babel-plugin-tsconfig-paths-module-resolver\n```\n\nSpecify the plugin in your `.babelrc` (or [equivalent configuration file](https://babeljs.io/docs/en/config-files#configuration-file-types)).\n\n```js\n{\n  \"presets\": [\n    // ...\n    \"@babel/preset-typescript\",\n    // ...\n  ],\n  \"plugins\": [\n    // add this to your babel config file in `plugins`\n    // 👇👇👇\n    \"tsconfig-paths-module-resolver\"\n    // 👆👆👆\n    // ...\n  ]\n}\n```\n\nThat's it! [Paths from your tsconfig.json][2] should now work!\n\n## Advanced usage\n\n`babel-plugin-tsconfig-paths-module-resolver` accepts the same options as [`babel-plugin-module-resolver`](https://github.com/tleunen/babel-plugin-module-resolver/blob/master/DOCS.md).\n\nYou can supply those extra options in your babel configuration file like so:\n\n```js\n{\n  \"presets\": [\n    // ...\n    \"@babel/preset-typescript\",\n    // ...\n  ],\n  \"plugins\": [\n    // ...\n    [\n      \"tsconfig-paths-module-resolver\",\n      // add extra options here\n      // 👇👇👇\n      {\n        // see here:\n        // https://github.com/tleunen/babel-plugin-module-resolver/blob/master/DOCS.md\n      }\n      // 👆👆👆\n    ]\n  ]\n};\n```\n\n### `resolvePath` and `createResolvePath`\n\n[`babel-plugin-module-resolver`][0] includes [a configuration option](https://github.com/tleunen/babel-plugin-module-resolver/blob/master/DOCS.md#resolvepath) to allow you to programmatically resolve your imports.\n\nThis plugin provides a `resolvePath` implementation powered by [`tsconfig-paths`][1]. If you'd like to implement your own `resolvePath` implementation while still utilizing this plugin's default implementation, you can separately import `createResolvePath` that returns a `resolvePath` implementation.\n\n```js\nconst createResolvePath = require('babel-plugin-tsconfig-paths-module-resolver/create-resolve-path');\nconst defaultResolvePath = createResolvePath();\n\n/**\n * @param sourceFile {string} the input source path\n * @param currentFile {string} the absolute path of the current file\n * @param opts {any} the options as passed to the Babel config\n * @return {string}\n */\nfunction customResolvePath(sourceFile, currentFile, opts) {\n  // ...\n  const result = defaultResolvePath(sourceFile, currentFile, opts);\n  // ...\n\n  return result;\n}\n\n// .babelrc.js\nmodule.exports = {\n  presets: [\n    // ...\n    '@babel/preset-typescript',\n    // ...\n  ],\n  plugins: [\n    // ...\n    [\n      'tsconfig-paths-module-resolver',\n      {\n        // 👇👇👇\n        resolvePath: customResolvePath,\n        // 👆👆👆\n      },\n    ],\n  ],\n};\n```\n\n[0]: https://github.com/tleunen/babel-plugin-module-resolver\n[1]: https://github.com/dividab/tsconfig-paths\n[2]: https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping\n[3]: https://badgen.net/npm/dw/babel-plugin-module-resolver\n[4]: https://www.npmjs.com/package/babel-plugin-module-resolver\n[5]: https://badgen.net/npm/dw/tsconfig-paths\n[6]: https://www.npmjs.com/package/tsconfig-paths\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricokahler%2Fbabel-plugin-tsconfig-paths-module-resolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fricokahler%2Fbabel-plugin-tsconfig-paths-module-resolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricokahler%2Fbabel-plugin-tsconfig-paths-module-resolver/lists"}