{"id":13826549,"url":"https://github.com/vihanb/babel-plugin-wildcard","last_synced_at":"2025-04-05T05:04:02.092Z","repository":{"id":52135721,"uuid":"88802818","full_name":"vihanb/babel-plugin-wildcard","owner":"vihanb","description":"Wildcard imports import a directories JS files","archived":false,"fork":false,"pushed_at":"2021-05-07T00:26:55.000Z","size":82,"stargazers_count":185,"open_issues_count":23,"forks_count":27,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T08:01:44.234Z","etag":null,"topics":["babel-plugin"],"latest_commit_sha":null,"homepage":null,"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/vihanb.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}},"created_at":"2017-04-20T00:21:57.000Z","updated_at":"2025-01-21T21:38:26.000Z","dependencies_parsed_at":"2022-08-23T21:50:50.990Z","dependency_job_id":null,"html_url":"https://github.com/vihanb/babel-plugin-wildcard","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihanb%2Fbabel-plugin-wildcard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihanb%2Fbabel-plugin-wildcard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihanb%2Fbabel-plugin-wildcard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihanb%2Fbabel-plugin-wildcard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vihanb","download_url":"https://codeload.github.com/vihanb/babel-plugin-wildcard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246963989,"owners_count":20861581,"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"],"created_at":"2024-08-04T09:01:40.092Z","updated_at":"2025-04-05T05:04:02.062Z","avatar_url":"https://github.com/vihanb.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# babel-plugin-wildcard\n\nAllows you to `import` all files from a directory at compile-time.\n\n## Installation\n\n```sh\n$ npm install babel-plugin-wildcard\n```\n\n## Usage\n\n### Via `.babelrc` (Recommended)\n\n**.babelrc**\n\n```json\n{\n  \"plugins\": [\"wildcard\"]\n}\n```\n\n### Via CLI\n\n```sh\n$ babel --plugins include script.js\n```\n\n### Via Node API\n\n```javascript\nrequire('babel').transform('code', {\n  plugins: ['wildcard']\n});\n```\n\n## Example\n\nWith the following folder structure:\n\n```\n|- index.js\n|- dir\n    |- a.js\n    |- b.js\n    |- c.js\n```\n\nthe following JS:\n\n```javascript\nimport * as Items from './dir';\n```\n\nwill be compiled to:\n\n```javascript\nconst Items = {};\nimport _wcImport from \"./dir/a\";\nItems.A = _wcImport;\nimport _wcImport1 from \"./dir/b\";\nItems.B = _wcImport1;\nimport _wcImport2 from \"./dir/c\";\nItems.C = _wcImport2;\n```\n\nmeaning you will be able to access the items using `Items.A` and `Items.B`.\n\n---\n\nYou can also selectively choose files using:\n\n```javascript\nimport { A, C } from \"dir/*\";\n```\n\nwhich in the above example would convert to:\n\n```\nimport A from \"./dir/a\";\nimport C from \"./dir/c\";\n```\n\nThe above is like doing:\n\n```\nimport * as temp from \"dir\";\nconst { A, C } = temp;\n```\n\n---\n\nThere is also simple Glob support so given the directory structure:\n\n```\n|- index.js\n|- dir\n    |- a.js\n    |- a.spec.js\n    |- b.js\n    |- b.spec.js\n```\n\nthis import:\n\n```javascript\nimport * as tests from './dir/*.spec';\n```\n\nwill compile to:\n\n```javascript\nimport aSpec from './dir/a.spec';\nimport bSpec from './dir/b.spec';\n```\n\n---\n\nFiles are automatically camel-cased and in the `import` statements the extensions are clipped unless specified otherwise (see below)\n\n## Information\n\n - File extensions are removed in the resulting variable. Dotfiles will be imported without their preceding `.` (e.g. `.foo` -\u003e `Foo` or `foo` depending on settings)\n - in an `import { ... } from 'foo/*'`, the identifiers inside { ... } are the same as what their name\n would be if you were to import the whole directory. This means it is the files' names' pascal/camel-cased and extensions removed etc. by default (depending on settings of course).\n\n## Options\n\n`babel-plugin-wildcard` allows you to change various settings by providing an options object by using the following instead:\n\n```javascript\n{\n    plugins: [\n        ['wildcard', { options }]\n    ]\n}\n```\n\nwhere `{ options }` is the options object. The following options are available:\n\n### `exts`\nBy default, the files with the following extensions: `[\"js\", \"es6\", \"es\", \"jsx\"]`, will be imported. You can change this using:\n\n```javascript\n{\n    plugins: [\n        ['wildcard', {\n            'exts': [\"js\", \"es6\", \"es\", \"jsx\", \"javascript\"]\n        }]\n    ]\n}\n```\n\nIf you add the extension `\"\"`, it will also import subdirectories.\n\n### `nostrip`\nBy default, the file extension will be removed in the generated `import` statements, you can change this using:\n\n```javascript\n{\n    plugins: [\n        ['wildcard', {\n            'nostrip': true\n        }]\n    ]\n}\n```\n\nThis is useful when the extension of your source files is different from the outputted ones. (e.g. `.jsx` to `.js`).\n\n### `useCamelCase`\nBy default the name is converted to PascalCase, if you prefer camelCase, you may set this option to true:\n\n```\n{\n    plugins: [\n        ['wildcard', {\n            'useCamelCase': true\n        }]\n    ]\n}\n```\n\n### `noModifyCase`\nBy default, the name will be automatically pascal cased, the following regex is used to extract the words, those words then have their first letter capitalized and are joined together:\n\n```\n[A-Z][a-z]+(?![a-z])|[A-Z]+(?![a-z])|([a-zA-Z\\d]+(?=-))|[a-zA-Z\\d]+(?=_)|[a-z]+(?=[A-Z])|[A-Za-z0-9]+\n```\n\nyou can disable this behavior using:\n\n```javascript\n{\n    plugins: [\n        ['wildcard', {\n            'noModifyCase': true\n        }]\n    ]\n}\n```\n\nExtensions are still removed (except dotfiles, see \"Information\").\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvihanb%2Fbabel-plugin-wildcard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvihanb%2Fbabel-plugin-wildcard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvihanb%2Fbabel-plugin-wildcard/lists"}