{"id":15184896,"url":"https://github.com/shunnnet/vue-caster","last_synced_at":"2026-01-07T02:03:08.853Z","repository":{"id":250897396,"uuid":"835473802","full_name":"shunnNet/vue-caster","owner":"shunnNet","description":"Command line tool that can switch Vue versions.","archived":false,"fork":false,"pushed_at":"2024-07-30T16:26:23.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T07:30:07.014Z","etag":null,"topics":["vue","vue-demi","vue2","vue3"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shunnNet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-07-29T23:14:27.000Z","updated_at":"2024-07-30T16:26:26.000Z","dependencies_parsed_at":"2024-07-30T18:29:31.682Z","dependency_job_id":"20b65a49-e50e-4fc2-b1ea-0674a99d4395","html_url":"https://github.com/shunnNet/vue-caster","commit_stats":null,"previous_names":["shunnnet/vue-caster"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shunnNet%2Fvue-caster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shunnNet%2Fvue-caster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shunnNet%2Fvue-caster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shunnNet%2Fvue-caster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shunnNet","download_url":"https://codeload.github.com/shunnNet/vue-caster/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245719773,"owners_count":20661311,"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":["vue","vue-demi","vue2","vue3"],"created_at":"2024-09-27T17:41:54.132Z","updated_at":"2026-01-07T02:03:08.801Z","avatar_url":"https://github.com/shunnNet.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🛠️ vue-caster\n- [🛠️ vue-caster](#️-vue-caster)\n  - [How this works?](#how-this-works)\n  - [Usage](#usage)\n  - [Why](#why)\n  - [TODO](#todo)\n  - [License](#license)\n\nThis is a command line tool that can switch between Vue versions. It can be used in conjunction with [vue-demi](https://github.com/vueuse/vue-demi) for developing components for Vue 2 and Vue 3.\n\n## How this works?\nThe way this package works is by using [npm install alias](https://docs.npmjs.com/cli/v8/commands/npm-install). \n\nFirst, install this package as \"vue\". Then, in the same project, install different versions of `Vue` under different names, such as `vue2.7`, `vue2.6`, `vue3`. Next, run the command line to switch `Vue` versions, and `vue-caster` will export the corresponding version of Vue.\n\nIf you are familiar with `vue-demi`, then the way `vue-caster` works is similar to `vue-demi`.\n\n## Usage\n1. Install `vue-caster` as `vue`:\n\n```bash\nnpm install -D vue@npm:vue-caster vue-demi\n```\n\n2. Install different versions of `Vue` with different names:\n\n```bash\nnpm install vue2.7@npm:vue@2.7.16\nnpm install vue3@npm:vue@3.4.34\n```\n\n3. Switch between Vue versions:\n```bash\n# v-cast \u003cversion\u003e \u003calias\u003e\nv-cast 2.7 vue2.7\nvue-demi-switch 2.7 vue2.7\n\n# Switch to Vue 3\nv-cast 3 vue3\nvue-demi-switch 3 vue3\n```\n\n4. Import Vue in your code, use it as usual:\n\n```js\n// If Vue 2\nimport Vue from 'vue';\n\n// If Vue 3\nimport { ref } from 'vue';\n```\n\nOr you can directly import from `vue-demi`\n\n```js\nimport { version } from 'vue-demi'; // is the the version of Vue you are using\nconsole.log(version); // version of Vue you are using\n```\n\nWhen you want to publish your package using `Vite`, just mark `vue` as external in `vite.config.js`:\n\n```js\nexport default {\n  optimizeDeps: {\n    exclude: ['vue-demi', 'vue'],\n  },\n  rollupInputOptions: {\n    external: ['vue-demi', 'vue'],\n  },\n};\n```\n\nWhen you need to bundle or use `vitest`, you will need `vue-demi`'s `isVue2` and `isVue3` to switch build configurations. You can refer to the `vite.config.ts` in the `/example` directory.\n\n## Why\nYou might ask, why do we still need `vue-caster` when we already have `vue-demi`? The main reason is that when developing components that are compatible with both Vue 2 and Vue 3, it's difficult to use `.vue` files with only `vue-demi`. You might want to develop using TypeScript in `.vue` files, or for various reasons, you need to bundle it, but you find that there can only be one version of `vue` in `node_modules`. So when you want to bundle or test, version error messages pop up because they all import or require `vue`.\n\nCan Vite `resolve.alias` solve this problem? No, because although alias can convert runtime code, it cannot handle the import or require of build tools.\n\nTo solve this problem, you could install different versions of Vue in different projects or pull out the packages with version dependency errors for customization. These are not comfortable solutions.\n\nThus, `vue-caster` was created. It is a proxy tool for Vue that can be used as different versions of Vue. Since it is installed as the name \"vue\" at the package level, the aforementioned path conversion issues are resolved.\n\n## TODO\n- [ ] Issue when direct vue import in vue-demi (entry not found: ./dist)\n- [ ] vue-test-utils type error\n- [ ] vite-plugin-dts cannot rollup types.\n- [ ] There are still some of vue exports not be handled.\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshunnnet%2Fvue-caster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshunnnet%2Fvue-caster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshunnnet%2Fvue-caster/lists"}