{"id":22423388,"url":"https://github.com/prantlf/babel-plugin-transform-modules-requirejs-babel","last_synced_at":"2025-08-01T07:32:23.335Z","repository":{"id":143846462,"uuid":"445957455","full_name":"prantlf/babel-plugin-transform-modules-requirejs-babel","owner":"prantlf","description":"A Babel plugin transforming ESM modules to AMD modules for processing by RequireJS with the requirejs-babel7 plugin.","archived":false,"fork":false,"pushed_at":"2022-02-08T00:59:35.000Z","size":35,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-05T19:47:24.151Z","etag":null,"topics":["amd","babel","babel-plugin","browser","module","plugin","requirejs","requirejs-babel","requirejs-babel7","transform"],"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/prantlf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-01-09T00:14:53.000Z","updated_at":"2022-01-09T20:23:53.000Z","dependencies_parsed_at":"2023-07-25T22:00:15.121Z","dependency_job_id":null,"html_url":"https://github.com/prantlf/babel-plugin-transform-modules-requirejs-babel","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fbabel-plugin-transform-modules-requirejs-babel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fbabel-plugin-transform-modules-requirejs-babel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fbabel-plugin-transform-modules-requirejs-babel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fbabel-plugin-transform-modules-requirejs-babel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prantlf","download_url":"https://codeload.github.com/prantlf/babel-plugin-transform-modules-requirejs-babel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228348371,"owners_count":17905899,"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":["amd","babel","babel-plugin","browser","module","plugin","requirejs","requirejs-babel","requirejs-babel7","transform"],"created_at":"2024-12-05T18:11:01.170Z","updated_at":"2025-08-01T07:32:23.325Z","avatar_url":"https://github.com/prantlf.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# babel-plugin-transform-modules-requirejs-babel\n\n[![Latest version](https://img.shields.io/npm/v/babel-plugin-transform-modules-requirejs-babel)\n ![Dependency status](https://img.shields.io/librariesio/release/npm/babel-plugin-transform-modules-requirejs-babel)\n](https://www.npmjs.com/package/babel-plugin-transform-modules-requirejs-babel)\n\nA [Babel] plugin transforming ESM modules to AMD modules, so that they will be processable by [RequireJS] with the help of the [requirejs-babel7] plugin.\n\nThe built-in plugin for the AMD module transformation - [@babel/plugin-transform-modules-amd] - covers only a simple scenario transform an ESM code base, which used AMD only as module format, without additional other RequireJS features. This plugin supports scenarios using all capabilities of RequireJS, above all:\n\n* Mixing ESM and AMD modules at any dependency level.\n* If an ESM module contains a single default export, it will be exported from the AMD module without wrapping to `{ default: ... }` to keep the compatibility. An AMD module can be rewritten to ESM and vice-versa anytime.\n* AMD module bundles with multiple `define` statements are recognised.\n\n### Table of Contents\n\n- [History](#history)\n- [Installation](#installation-and-getting-started)\n- [Babel Configuration Examples](#babel-configuration-examples)\n- [Contributing](#contributing)\n- [License](#license)\n\n## History\n\nThis plugin replaces a couple of plugins usually used together with [requirejs-babel7]: [@babel/plugin-transform-modules-amd], [babel-plugin-amd-checker], [babel-plugin-amd-default-export] and [babel-plugin-module-resolver-standalone]. An example of a Babel configuration using those plugins:\n\n```js\n{\n  plugins: [\n    'amd-checker',\n    'transform-modules-amd',\n    [\n      'module-resolver',\n      {\n        resolvePath: function (sourcePath, currentFile, opts) {\n          // Ignore paths with other plugins applied and the three built-in\n          // pseudo-modules of RequireJS.\n          if (sourcePath.indexOf('!') \u003c 0 \u0026\u0026 sourcePath !== 'require' \u0026\u0026\n            sourcePath !== 'module' \u0026\u0026 sourcePath !== 'exports') {\n            return 'es6!' + sourcePath;\n          }\n        }\n      }\n    ],\n    ['amd-default-export', { addDefaultProperty: false }]\n  ]\n}\n```\n\nTheir combination did not support mixing ESM and AMD modules at any dependency level. Skipping of AMD modules had to be handled by catching an error of a special class, which needed to wrap Babel programmatically. The new plugin covers amm problems of the built-in AMD transformation, which the previous ones did, without any drawbacks.\n\n## Installation\n\nThis module can be installed in your project using [NPM], [PNPM] or [Yarn]. Make sure, that you use [Node.js] version 6 or newer.\n\n```sh\nnpm i -D babel-plugin-transform-modules-requirejs-babel\npnpm i -D babel-plugin-transform-modules-requirejs-babel\nyarn add babel-plugin-transform-modules-requirejs-babel\n```\n\n## Babel Configuration Examples\n\nPrevent the transpiler to wrap source files that are already wrapped by `define` or `require` as AMD modules:\n\n```js\n{\n  plugins: ['transform-modules-requirejs-babel']\n}\n```\n\nCustomising the default module path transformation:\n\n```js\n{\n  plugins: [\n    [\n      'transform-modules-requirejs-babel',\n      {\n        resolvePath: function (sourcePath, currentFile, opts) {\n          // Ignore paths with other plugins applied and the three built-in\n          // pseudo-modules of RequireJS.\n          if (sourcePath.indexOf('!') \u003c 0 \u0026\u0026 sourcePath !== 'require' \u0026\u0026\n            sourcePath !== 'module' \u0026\u0026 sourcePath !== 'exports') {\n            return 'es6!' + sourcePath;\n          }\n        }\n      }\n    ]\n  ]\n}\n```\n\n## Contributing\n\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.\n\n## License\n\nCopyright (c) 2022-2025 Ferdinand Prantl\n\nLicensed under the MIT license.\n\n[Node.js]: http://nodejs.org/\n[NPM]: https://www.npmjs.com/\n[PNPM]: https://pnpm.io/\n[Yarn]: https://yarnpkg.com/\n[Babel]: http://babeljs.io\n[RequireJS]: https://requirejs.org/\n[requirejs-babel7]: https://www.npmjs.com/package/requirejs-babel7\n[@babel/plugin-transform-modules-amd]: https://www.npmjs.com/package/@babel/plugin-transform-modules-amd\n[@babel/plugin-transform-modules-amd]: https://www.npmjs.com/package/requirejs-babel7\n[babel-plugin-amd-checker]: https://www.npmjs.com/package/babel-plugin-amd-checker\n[babel-plugin-amd-default-export]: https://www.npmjs.com/package/babel-plugin-amd-default-export\n[babel-plugin-module-resolver-standalone]: https://www.npmjs.com/package/babel-plugin-module-resolver-standalone\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fbabel-plugin-transform-modules-requirejs-babel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprantlf%2Fbabel-plugin-transform-modules-requirejs-babel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fbabel-plugin-transform-modules-requirejs-babel/lists"}