npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-caster

v0.1.3

Published

Command line tool that can switch Vue versions.

Downloads

4

Readme

🛠️ vue-caster

This is a command line tool that can switch between Vue versions. It can be used in conjunction with vue-demi for developing components for Vue 2 and Vue 3.

How this works?

The way this package works is by using npm install alias.

First, 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.

If you are familiar with vue-demi, then the way vue-caster works is similar to vue-demi.

Usage

  1. Install vue-caster as vue:
npm install -D vue@npm:vue-caster vue-demi
  1. Install different versions of Vue with different names:
npm install vue2.7@npm:[email protected]
npm install vue3@npm:[email protected]
  1. Switch between Vue versions:
# v-cast <version> <alias>
v-cast 2.7 vue2.7
vue-demi-switch 2.7 vue2.7

# Switch to Vue 3
v-cast 3 vue3
vue-demi-switch 3 vue3
  1. Import Vue in your code, use it as usual:
// If Vue 2
import Vue from 'vue';

// If Vue 3
import { ref } from 'vue';

Or you can directly import from vue-demi

import { version } from 'vue-demi'; // is the the version of Vue you are using
console.log(version); // version of Vue you are using

When you want to publish your package using Vite, just mark vue as external in vite.config.js:

export default {
  optimizeDeps: {
    exclude: ['vue-demi', 'vue'],
  },
  rollupInputOptions: {
    external: ['vue-demi', 'vue'],
  },
};

When 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.

Why

You 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.

Can Vite resolve.alias solve this problem? No, because although alias can convert runtime code, it cannot handle the import or require of build tools.

To 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.

Thus, 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.

TODO

  • [ ] Issue when direct vue import in vue-demi (entry not found: ./dist)
  • [ ] vue-test-utils type error
  • [ ] vite-plugin-dts cannot rollup types.
  • [ ] There are still some of vue exports not be handled.

License

MIT