{"id":13435197,"url":"https://github.com/tleunen/babel-plugin-module-resolver","last_synced_at":"2025-05-12T13:24:20.648Z","repository":{"id":36515548,"uuid":"40821265","full_name":"tleunen/babel-plugin-module-resolver","owner":"tleunen","description":"Custom module resolver plugin for Babel","archived":false,"fork":false,"pushed_at":"2024-04-18T17:49:37.000Z","size":1683,"stargazers_count":3476,"open_issues_count":110,"forks_count":203,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-05-02T09:49:02.487Z","etag":null,"topics":["babel","babel-plugin","resolver"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/tleunen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2015-08-16T14:05:20.000Z","updated_at":"2025-04-28T13:51:11.000Z","dependencies_parsed_at":"2023-01-17T02:13:52.327Z","dependency_job_id":"9a0f5f41-ffdd-453c-88e6-b7cfab0bdecc","html_url":"https://github.com/tleunen/babel-plugin-module-resolver","commit_stats":{"total_commits":219,"total_committers":55,"mean_commits":3.981818181818182,"dds":0.6849315068493151,"last_synced_commit":"620df49418e07aab1f5f3d668b02e56b27b89e94"},"previous_names":["tleunen/babel-plugin-module-alias"],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tleunen%2Fbabel-plugin-module-resolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tleunen%2Fbabel-plugin-module-resolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tleunen%2Fbabel-plugin-module-resolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tleunen%2Fbabel-plugin-module-resolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tleunen","download_url":"https://codeload.github.com/tleunen/babel-plugin-module-resolver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253745753,"owners_count":21957436,"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","resolver"],"created_at":"2024-07-31T03:00:33.715Z","updated_at":"2025-05-12T13:24:20.625Z","avatar_url":"https://github.com/tleunen.png","language":"JavaScript","readme":"# babel-plugin-module-resolver\n[![Maintenance Status][status-image]][status-url] [![NPM version][npm-image]][npm-url] [![Build Status Linux][circleci-image]][circleci-url] [![Build Status Windows][appveyor-image]][appveyor-url] [![Coverage Status][coverage-image]][coverage-url]\n\nA [Babel](http://babeljs.io) plugin to add a new resolver for your modules when compiling your code using Babel. This plugin allows you to add new \"root\" directories that contain your modules. It also allows you to setup a custom alias for directories, specific files, or even other npm modules.\n\n## Description\n\nThis plugin can simplify the require/import paths in your project. For example, instead of using complex relative paths like `../../../../utils/my-utils`, you can write `utils/my-utils`. It will allow you to work faster since you won't need to calculate how many levels of directory you have to go up before accessing the file.\n\n```js\n// Use this:\nimport MyUtilFn from 'utils/MyUtilFn';\n// Instead of that:\nimport MyUtilFn from '../../../../utils/MyUtilFn';\n\n// And it also work with require calls\n// Use this:\nconst MyUtilFn = require('utils/MyUtilFn');\n// Instead of that:\nconst MyUtilFn = require('../../../../utils/MyUtilFn');\n```\n\n## Getting started\n\nInstall the plugin\n\n```\nnpm install --save-dev babel-plugin-module-resolver\n```\nor\n```\nyarn add --dev babel-plugin-module-resolver\n```\n\nSpecify the plugin in your `.babelrc` with the custom root or alias. Here's an example:\n```json\n{\n  \"plugins\": [\n    [\"module-resolver\", {\n      \"root\": [\"./src\"],\n      \"alias\": {\n        \"test\": \"./test\",\n        \"underscore\": \"lodash\"\n      }\n    }]\n  ]\n}\n```\n\n**.babelrc.js version**\nSpecify the plugin in your `.babelrc.js` file with the custom root or alias. Here's an example:\n```\n\nconst plugins = [\n  [\n    require.resolve('babel-plugin-module-resolver'),\n    {\n      root: [\"./src/\"],\n      alias: {\n        \"test\": \"./test\"\n      }\n    }\n\n  ]\n\n];\n\n```\nGood example: // https://gist.github.com/nodkz/41e189ff22325a27fe6a5ca81df2cb91\n\n\n## Documentation\n\nbabel-plugin-module-resolver can be configured and controlled easily, check the [documentation](DOCS.md) for more details\n\nAre you a plugin author (e.g. IDE integration)? We have [documented the exposed functions](DOCS.md#for-plugin-authors) for use in your plugins!\n\n## ESLint plugin\n\nIf you're using ESLint, you should use [eslint-plugin-import][eslint-plugin-import], and [eslint-import-resolver-babel-module][eslint-import-resolver-babel-module] to remove falsy unresolved modules. If you want to have warnings when aliased modules are being imported by their relative paths, you can use [eslint-plugin-module-resolver](https://github.com/HeroProtagonist/eslint-plugin-module-resolver).\n\n## Editors autocompletion\n\n- Atom: Uses [atom-autocomplete-modules][atom-autocomplete-modules] and enable the `babel-plugin-module-resolver` option.\n- VS Code: Configure the [path mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) in `jsconfig.json` (`tsconfig.json` for TypeScript), e.g.:\n\n```js\n{\n  \"compilerOptions\": {\n    \"baseUrl\": \".\",\n    \"paths\": {\n      \"*\": [\"src/*\"],\n      \"test/*\": [\"test/*\"],\n      \"underscore\": [\"lodash\"]\n    }\n  }\n}\n```\n\n- IntelliJ/WebStorm: You can mark your module directories as \"resources root\" e.g if you have `../../../utils/MyUtilFn` you can mark\n  `../../../utils` as \"resources root\". This has the problem that your alias also has to be named `utils`. The second option is to add\n  a `webpack.config.js` to your project and use it under File-\u003eSettings-\u003eLanguages\u0026Frameworks-\u003eJavaScript-\u003eWebpack. This will trick webstorm\n  into resolving the paths and you can use any alias you want e.g.:\n\n```js\nvar path = require('path');\n\nmodule.exports = {\n  resolve: {\n    extensions: ['.js', '.json', '.vue'],\n    alias: {\n      utils: path.resolve(__dirname, '../../../utils/MyUtilFn'),\n    },\n  },\n};\n```\n\n\n## License\n\nMIT, see [LICENSE.md](/LICENSE.md) for details.\n\n## Who is using babel-plugin-module-resolver ?\n\n- Algolia: [InstantSearch.js](https://github.com/algolia/instantsearch.js)\n- Airbnb: [Lottie React Native](https://github.com/airbnb/lottie-react-native)\n- AppDirect\n- Callstack: [React Native Paper](https://github.com/callstack/react-native-paper)\n- Codility\n- Eleme: [Element](https://github.com/ElemeFE/element)\n- Expo: [Expo SDK](https://github.com/expo/expo/tree/master/packages/babel-preset-expo)\n- FormidableLabs: [Victory Native](https://github.com/FormidableLabs/victory-native)\n- OpenCollective: [OpenCollective](https://github.com/opencollective/frontend)\n- React Community: [React Native Maps](https://github.com/react-community/react-native-maps)\n- Uber: [Seer](https://github.com/uber-web/Seer), [react-vis](https://github.com/uber/react-vis)\n- Quasar Framework: [Quasar](https://github.com/quasarframework/quasar)\n- Vuetify.js [Vuetify](https://github.com/vuetifyjs/vuetify)\n- Zeit: [Next.js](https://github.com/zeit/next.js)\n- Zenika: [Immutadot](https://github.com/Zenika/immutadot)\n\nAre you also using it? Send a PR!\n\n[status-image]: https://img.shields.io/badge/status-maintained-brightgreen.svg\n[status-url]: https://github.com/tleunen/babel-plugin-module-resolver\n\n[npm-image]: https://img.shields.io/npm/v/babel-plugin-module-resolver.svg\n[npm-url]: https://www.npmjs.com/package/babel-plugin-module-resolver\n\n[circleci-image]: https://img.shields.io/circleci/project/tleunen/babel-plugin-module-resolver/master.svg?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSItMTQyLjUgLTE0Mi41IDI4NSAyODUiPjxjaXJjbGUgcj0iMTQxLjciIGZpbGw9IiNERDQ4MTQiLz48ZyBpZD0iYSIgZmlsbD0iI0ZGRiI%2BPGNpcmNsZSBjeD0iLTk2LjQiIHI9IjE4LjkiLz48cGF0aCBkPSJNLTQ1LjYgNjguNGMtMTYuNi0xMS0yOS0yOC0zNC00Ny44IDYtNSA5LjgtMTIuMyA5LjgtMjAuNnMtMy44LTE1LjctOS44LTIwLjZjNS0xOS44IDE3LjQtMzYuNyAzNC00Ny44bDEzLjggMjMuMkMtNDYtMzUuMi01NS4zLTE4LjctNTUuMyAwYzAgMTguNyA5LjMgMzUuMiAyMy41IDQ1LjJ6Ii8%2BPC9nPjx1c2UgeGxpbms6aHJlZj0iI2EiIHRyYW5zZm9ybT0icm90YXRlKDEyMCkiLz48dXNlIHhsaW5rOmhyZWY9IiNhIiB0cmFuc2Zvcm09InJvdGF0ZSgyNDApIi8%2BPC9zdmc%2B\n[circleci-url]: https://circleci.com/gh/tleunen/babel-plugin-module-resolver\n\n[appveyor-image]: https://img.shields.io/appveyor/ci/tleunen/babel-plugin-module-resolver/master.svg?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgd2lkdGg9IjEyOCIgaGVpZ2h0PSIxMjgiIHZpZXdCb3g9IjAgMCAxMjggMTI4Ij48ZyBmaWxsPSIjMUJBMUUyIiB0cmFuc2Zvcm09InNjYWxlKDgpIj48cGF0aCBkPSJNMCAyLjI2NWw2LjUzOS0uODg4LjAwMyA2LjI4OC02LjUzNi4wMzd6Ii8%2BPHBhdGggZD0iTTYuNTM2IDguMzlsLjAwNSA2LjI5My02LjUzNi0uODk2di01LjQ0eiIvPjxwYXRoIGQ9Ik03LjMyOCAxLjI2MWw4LjY3LTEuMjYxdjcuNTg1bC04LjY3LjA2OXoiLz48cGF0aCBkPSJNMTYgOC40NDlsLS4wMDIgNy41NTEtOC42Ny0xLjIyLS4wMTItNi4zNDV6Ii8%2BPC9nPjwvc3ZnPg==\n[appveyor-url]: https://ci.appveyor.com/project/tleunen/babel-plugin-module-resolver\n\n[coverage-image]: https://codecov.io/gh/tleunen/babel-plugin-module-resolver/branch/master/graph/badge.svg\n[coverage-url]: https://codecov.io/gh/tleunen/babel-plugin-module-resolver\n\n[eslint-import-resolver-babel-module]: https://github.com/tleunen/eslint-import-resolver-babel-module\n[eslint-plugin-import]: https://github.com/benmosher/eslint-plugin-import\n[atom-autocomplete-modules]: https://github.com/nkt/atom-autocomplete-modules\n","funding_links":[],"categories":["HarmonyOS","JavaScript","Babel","Plugins"],"sub_categories":["Windows Manager","Module Resolution"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftleunen%2Fbabel-plugin-module-resolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftleunen%2Fbabel-plugin-module-resolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftleunen%2Fbabel-plugin-module-resolver/lists"}