{"id":21565151,"url":"https://github.com/cfware/babel-plugin-bare-import-rewrite","last_synced_at":"2025-06-13T01:05:05.532Z","repository":{"id":53120472,"uuid":"134065170","full_name":"cfware/babel-plugin-bare-import-rewrite","owner":"cfware","description":"Babel plugin to rewrite bare imports for use on web browsers.","archived":false,"fork":false,"pushed_at":"2021-04-05T23:24:54.000Z","size":68,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-30T21:21:11.159Z","etag":null,"topics":["babel-plugin","esm","esmodules"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cfware.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"tidelift":"npm/babel-plugin-bare-import-rewrite"}},"created_at":"2018-05-19T13:38:33.000Z","updated_at":"2025-01-19T11:28:50.000Z","dependencies_parsed_at":"2022-08-18T23:50:57.131Z","dependency_job_id":null,"html_url":"https://github.com/cfware/babel-plugin-bare-import-rewrite","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/cfware/babel-plugin-bare-import-rewrite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfware%2Fbabel-plugin-bare-import-rewrite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfware%2Fbabel-plugin-bare-import-rewrite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfware%2Fbabel-plugin-bare-import-rewrite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfware%2Fbabel-plugin-bare-import-rewrite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cfware","download_url":"https://codeload.github.com/cfware/babel-plugin-bare-import-rewrite/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfware%2Fbabel-plugin-bare-import-rewrite/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259559624,"owners_count":22876495,"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-plugin","esm","esmodules"],"created_at":"2024-11-24T10:18:35.592Z","updated_at":"2025-06-13T01:05:05.366Z","avatar_url":"https://github.com/cfware.png","language":"JavaScript","funding_links":["https://tidelift.com/funding/github/npm/babel-plugin-bare-import-rewrite","https://tidelift.com/subscription/pkg/npm-babel-plugin-bare-import-rewrite?utm_source=npm-babel-plugin-bare-import-rewrite\u0026utm_medium=referral\u0026utm_campaign=enterprise\u0026utm_term=repo"],"categories":[],"sub_categories":[],"readme":"# babel-plugin-bare-import-rewrite\n\n[![Travis CI][travis-image]][travis-url]\n[![Greenkeeper badge][gk-image]](https://greenkeeper.io/)\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![BSD-3-Clause][license-image]](LICENSE)\n\nBabel plugin to rewrite bare imports.  In theory this will become obsolete if/when\nbrowsers get support for import maps.  See [domenic/package-name-maps] for information\nabout the proposal.\n\n## Install babel-plugin-bare-import-rewrite\n\nThis module requires node.js 10 or above and `@babel/core`.\n\n```sh\nnpm i babel-plugin-bare-import-rewrite\n```\n\n## Usage\n\nAdd `bare-import-rewrite` to `plugins` in your babel settings.\n\n## Settings\n\n```json\n{\n\t\"plugins\": [\n\t\t[\"bare-import-rewrite\", {\n\t\t\t\"modulesDir\": \"/node_modules\",\n\t\t\t\"rootBaseDir\": \".\",\n\t\t\t\"alwaysRootImport\": [],\n\t\t\t\"ignorePrefixes\": [\"//\"],\n\t\t\t\"failOnUnresolved\": false,\n\t\t\t\"resolveDirectories\": [\"node_modules\"],\n\t\t\t\"processAtProgramExit\": false,\n\t\t\t\"preserveSymlinks\": true\n\t\t}]\n\t]\n}\n```\n\nIf the plugin settings object is omitted the defaults are used:\n```json\n{\n\t\"plugins\": [\"bare-import-rewrite\"]\n}\n```\n\n### modulesDir\n\nThe URL path in which files from the `node_modules` directory will be published on\nthe web server. This must be an absolute URL if provided (with or without hostname).\nDefault undefined.\n\n### rootBaseDir\n\nThe project base directory.  This should contain the package.json and node_modules\nof the application.  Default `process.cwd()`.\n\n### alwaysRootImport\n\nThis contains a list of module bare names which should always be forced to import from\nthe root node_modules.  `['**']` can be used to specify that all modules should be\nresolved from the root folder.  No attempt is made to verify that overridden modules\nare compatible.  Each element is used as a pattern to be processed with `minimatch`.\nDefault `[]`.\n\n### neverRootImport\n\nThis contains a list of module bare names which should never be forced to imported\nfrom the root node_modules.  Processed with `minimatch`.  Default `[]`.\n\nThis example will force all modules to be loaded from the root node_modules except\nfor `some-exception`:\n```json\n{\n\t\"alwaysRootImport\": [\"**\"],\n\t\"neverRootImport\": [\"some-exception\"]\n}\n```\n\n### failOnUnresolved\n\nBy default an error is logged when an import could not be resolved, but it does not fail babel compilation.\nSetting this option to true will fail babel compilation with details.\n\n### resolveDirectories\n\nArray of directories which should be search for resolving modules. If multiple directories are specified they\nare evaluated in order of importance. If the same module exists in both folders, the leftmost module directory is\nalways taken. Defaults to `['node_modules']`.\n\n### fsPath\n\nSetting this option `true` forces use of platform specific path separators.  This changes\nthe default value of `modulesDir` to the absolute filesystem path of `node_modules`.  This\nshould generally be used when using absolute filesystem paths for bundling.\n\n### ignorePrefixes\n\nThis option can be set to an array of strings.  Each represents a module name prefix\nto be ignored.\n\n### extensions\n\nA list of extensions to use in resolver. Default `['.mjs', '.js', '.json']`.\n\n### processAtProgramExit\n\nThis causes processing to occur during the babel `Program.exit` visitor.  In general\nthis option is not needed.\n\n### preserveSymlinks\n\nThis is passed to the `resolve` module.  Default `true`.\n\n### `.resolve(importModule, sourceFileName, pluginOptions)` - Resolve absolute path.\n\nThis function is used internally by the babel plugin, is exposed so it can be used\nby analyzers to build a list of scripts being imported.  The `pluginOptions` argument\ntakes the same values as the babel plugin and uses the same defaults.\n\n```js\nconst {resolve} = require('babel-plugin-bare-import-rewrite');\n\nconst importModule = '@polymer/lit-element';\nconst pluginOptions = {\n\t\"alwaysRootImport\": [\"@polymer/*\"],\n};\ntry {\n\tconst absPath = resolve(importModule, __filename, pluginOptions);\n\tconsole.log(`The requested module ${importModule} is in ${absPath}.`);\n} catch (e) {\n\tconsole.error(`Cound not resolve ${importModule}:`, e);\n}\n```\n\n## Web Server Support\n\nSome web server software has support for live translation of JavaScript sources.  These\nare meant for using during development and testing, a build step should be used to\nproduce static translated sources for production deployments.\n\n* [fastify-babel] can be used with [fastify] and [fastify-static]\n* [express-transform-bare-module-specifiers] can be used with [express]\n\nFeel free to open an issue or PR if you know of other node.js servers which can use this\nbabel plugin to perform bare import rewrites.\n\n## Running tests\n\nTests are provided by xo and ava.\n\n```sh\nnpm install\nnpm test\n```\n\n## Attribution\n\nThis module is based on code found in [polymer-build] and [polymer-analyzer].\n\n## `babel-plugin-bare-import-rewrite` for enterprise\n\nAvailable as part of the Tidelift Subscription.\n\nThe maintainers of `babel-plugin-bare-import-rewrite` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-babel-plugin-bare-import-rewrite?utm_source=npm-babel-plugin-bare-import-rewrite\u0026utm_medium=referral\u0026utm_campaign=enterprise\u0026utm_term=repo)\n\n[npm-image]: https://img.shields.io/npm/v/babel-plugin-bare-import-rewrite.svg\n[npm-url]: https://npmjs.org/package/babel-plugin-bare-import-rewrite\n[travis-image]: https://travis-ci.org/cfware/babel-plugin-bare-import-rewrite.svg?branch=master\n[travis-url]: https://travis-ci.org/cfware/babel-plugin-bare-import-rewrite\n[gk-image]: https://badges.greenkeeper.io/cfware/babel-plugin-bare-import-rewrite.svg\n[downloads-image]: https://img.shields.io/npm/dm/babel-plugin-bare-import-rewrite.svg\n[downloads-url]: https://npmjs.org/package/babel-plugin-bare-import-rewrite\n[license-image]: https://img.shields.io/npm/l/babel-plugin-bare-import-rewrite.svg\n[domenic/package-name-maps]: https://github.com/domenic/package-name-maps/\n[polymer-analyzer]: https://github.com/Polymer/tools/blob/219ab4f3f9f8773e75f8c6181109e8966082b9af/packages/analyzer/src/javascript/resolve-specifier-node.ts\n[polymer-build]: https://github.com/Polymer/tools/blob/219ab4f3f9f8773e75f8c6181109e8966082b9af/packages/build/src/babel-plugin-bare-specifiers.ts\n[fastify]: https://github.com/fastify/fastify#readme\n[fastify-static]: https://github.com/fastify/fastify-static#readme\n[fastify-babel]: https://github.com/cfware/fastify-babel#readme\n[express]: https://github.com/expressjs/express#readme\n[express-transform-bare-module-specifiers]: https://github.com/nodecg/express-transform-bare-module-specifiers#readme\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcfware%2Fbabel-plugin-bare-import-rewrite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcfware%2Fbabel-plugin-bare-import-rewrite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcfware%2Fbabel-plugin-bare-import-rewrite/lists"}