{"id":13417400,"url":"https://github.com/subwaytime/vite-aliases","last_synced_at":"2025-04-10T03:49:59.065Z","repository":{"id":43167248,"uuid":"310125318","full_name":"Subwaytime/vite-aliases","owner":"Subwaytime","description":"Alias auto generation for Vite","archived":false,"fork":false,"pushed_at":"2024-05-29T12:52:37.000Z","size":414,"stargazers_count":210,"open_issues_count":8,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-01T11:19:23.515Z","etag":null,"topics":["typescript","vite","vite-aliases","vite-plugin","vue3"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/vite-aliases","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/Subwaytime.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"subwaytime"}},"created_at":"2020-11-04T21:49:09.000Z","updated_at":"2024-09-15T16:17:52.000Z","dependencies_parsed_at":"2024-01-07T13:28:20.588Z","dependency_job_id":"6f875a31-02ad-4149-916c-38d3c8f532c9","html_url":"https://github.com/Subwaytime/vite-aliases","commit_stats":{"total_commits":231,"total_committers":6,"mean_commits":38.5,"dds":0.09090909090909094,"last_synced_commit":"cc35d4c14c29d91ed0784c0064e29e556701c58d"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subwaytime%2Fvite-aliases","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subwaytime%2Fvite-aliases/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subwaytime%2Fvite-aliases/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subwaytime%2Fvite-aliases/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Subwaytime","download_url":"https://codeload.github.com/Subwaytime/vite-aliases/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246922243,"owners_count":20855345,"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":["typescript","vite","vite-aliases","vite-plugin","vue3"],"created_at":"2024-07-30T22:00:36.487Z","updated_at":"2025-04-03T02:18:10.114Z","avatar_url":"https://github.com/Subwaytime.png","language":"TypeScript","funding_links":["https://github.com/sponsors/subwaytime"],"categories":["Plugins"],"sub_categories":["Framework-agnostic Plugins"],"readme":"\u003ch2 align=\"left\"\u003evite-aliases\u003c/h2\u003e\n\n\u003cp align=\"left\"\u003eAlias auto generation for Vite 6\u003c/p\u003e\n\n\u003cp align=\"left\"\u003e\n\u003ca href=\"https://www.npmjs.com/package/vite-aliases\"\u003e\n\u003cimg src=\"https://img.shields.io/npm/v/vite-aliases?color=222\u0026style=flat-square\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n## Usage\n\nInstall\n\n```bash\nnpm i vite-aliases -D\n```\n\nAdd it to `vite.config.js`\n\n```ts\n// vite.config.js\nimport { ViteAliases } from 'vite-aliases'\n\nexport default {\n  plugins: [\n    ViteAliases()\n  ]\n};\n\n```\n\nAdd this to `package.json` (Plugin is only available for ESM)\n```json\n{\n  \"type\": \"module\"\n}\n```\n\nThat's it!\n\n\u003cp\u003e\n\u003cbr/\u003e\nBased on your Folderstructure, it will now automatically generate all needed aliases.\n\u003cbr /\u003e\nYou can configure it to any desired Depth, but it is recommend to stay on the first Level!\n\u003cbr /\u003e\nFurthermore it will use your native OS filesystem, so it works on Linux, Mac, Windows and other OS.\n\u003c/p\u003e\n\n\u003cbr /\u003e\nThis structure:\n\n```\nsrc\n  assets\n  components\n  pages\n  store\n  utils\n```\n\nwill generate the following:\n\n```ts\n[\n  {\n    find: '~',\n    replacement: '${your_project_path}/src'\n  },\n  {\n    find: '~assets',\n    replacement: '${your_project_path}/src/assets'\n  },\n  {\n    find: '~components',\n    replacement: '${your_project_path}/src/components'\n  },\n  {\n    find: '~pages',\n    replacement: '${your_project_path}/src/pages'\n  },\n  {\n    find: '~store',\n    replacement: '${your_project_path}/src/store'\n  },\n  {\n    find: '~utils',\n    replacement: '${your_project_path}/src/utils'\n  },\n]\n```\n\n## Best Practice\n\n`vite-aliases` is meant to simply take the first Layer of your folders and turn it into useful Shortcuts.\n\u003cbr /\u003e\nTherefore i advise you to use the default Configuration and not use folders with the same name, otherwise it will create an Error.\n\nIf however you need duplicate Foldernames, enable `adjustDuplicates`.\n\u003cbr /\u003e\nThis will turn the entire Filepath of said duplicate into the alias itself, like shown in the Example below.\n\nExample:\n```\n`src/components` -\u003e `~components`\n`src/pages/components` -\u003e `~pagesComponents`\n`src/test/new/partials/components` -\u003e `~testNewPartialsComponents`\n```\nand so on..\n\n## Configuration\n\nCurrent available options:\n\n```ts\nViteAliases({\n  /**\n  * Relative path to the project directory\n  */\n  dir: 'src',\n\n  /**\n  * Prefix symbol for the aliases\n  */\n  prefix: '~',\n\n  /**\n  * Allow searching for subdirectories\n  */\n  deep: true,\n\n  /**\n  * Search depthlevel for subdirectories\n  */\n  depth: 1,\n\n  /**\n  * Creates a Logfile\n  * use `logPath` to change the location\n  */\n  createLog: false,\n\n  /**\n  * Path for Logfile\n  */\n  logPath: 'src/logs',\n\n  /**\n  * Create global project directory alias\n  */\n  createGlobalAlias: true,\n\n  /**\n  * Turns duplicates into camelCased path aliases\n  */\n  adjustDuplicates: false,\n\n  /**\n  * Used paths in JS/TS configs will now be relative to baseUrl\n  */\n  useAbsolute: false,\n\n  /**\n  * Adds seperate index paths\n  * approach created by @davidohlin\n  */\n  useIndexes: false,\n\n  /**\n  * Generates paths in IDE config file\n  * works with JS or TS\n  */\n  useConfig: true,\n\n  /**\n  * Override config paths\n  */\n  ovrConfig: false,\n\n  /**\n  * Will generate Paths in tsconfig\n  * used in combination with `useConfig`\n  * Typescript will be auto detected\n  */\n  dts: false,\n\n  /**\n  * Disables any terminal output\n  */\n  silent: true,\n\n  /**\n  * Root path of Vite project\n  */\n  root: process.cwd()\n});\n```\n\n## Thanks\n\nThanks to [@brattonross](https://github.com/brattonross) and [@antfu](https://github.com/antfu),\ndue to this tiny library beeing inspired by both projects:\n\n[vite-plugin-voie](https://github.com/vamplate/vite-plugin-voie)\n\n[unplugin-vue-components](https://github.com/antfu/unplugin-vue-components).\n\n## License\n\nMIT License © 2020-PRESENT [Leon Langer](https://github.com/subwaytime)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubwaytime%2Fvite-aliases","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsubwaytime%2Fvite-aliases","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubwaytime%2Fvite-aliases/lists"}