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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-variant

v1.0.0

Published

[中文](README.zh-CN.md) | English

Readme

Vite Plugin Variant

中文 | English

Introduction

vite-plugin-variant is a vite plugin for managing multi-channel differentiated source code. Unlike other vite plugins, the principle of vite-plugin-variant is to filter out the current channel files from the multi-channel source code directory, and then update the src directory, in other words, the process from the multi-channel src(MCS) to the current channel src(FCS), instead of making some work based on the src directory, so it can be very compatible with other vite plugins.

  • MCS:multi-channel src
  • FCS:final channel src

Feature

  • Support adding, deleting and updating files with immediate effect(HMR)
  • Support dynamic switching of channels
  • Support for defining multi-channel global variables
  • Support All vite projects(including uniapp)

Usage

1、install

npm i vite-plugin-variant -D

2、config

Add configuration in vite.config.ts

import variant from "vite-plugin-variant";

export default defineConfig({
  plugins: [
    variant({
      mcsCurrent: "channelA", // current channel
      mcsDefine: {
        channelA: {}, // global variable for channel A ....
        channelB: {}, // global variable for channel B ....
      },
    }),
    // other plugins
  ],
});

Note:

  1. variant() needs to be placed at the first of the plugin list for better compatibility with other plugins.
  2. Change the value of mcsCurrent to switch channels, and it will be automatically redeployed in dev mode。

3、Source code directory

  1. Create a variants/main directory under the same level of src to store the default project source code.
  2. Create channel directories(such as channelA, channelB) under the variants directory as the source code of each channel difference.

Note: Assuming that the project needs to go online on two different channels, namely Huawei and Xiaomi, and they display different logo pictures, you can place their own logo pictures in their respective channel directories. If there is no logo picture in one channel, then use the default logo image in the main directory, and the same for other source files.

4、Global variable

Configure global variables for each channel in vite.config.ts

export default defineConfig({
  plugins: [
    variant({
      mcsCurrent: "huawei",
      mcsDefine: {
        xiaomi: {
          WEBSITE: "https://www.mi.com/",
        },
        huawei: {
          WEBSITE: "https://www.huawei.com/",
        },
      },
    }),
  ],
});

Note:

  1. The global variables defined in mcsDefine have the same effect as those defined in the define option of vite, but mcsDefine can better manager the variables of each channel。
  2. vite-plugin-variant will automatically generate variant-env.d.ts in the variants/main directory based on the global variables of the current channel to prevent TypeScript compilation errors.

You can use the global variables directly in the code:

import { ref } from "vue";
const flavor = ref(FLAVOR);
const website = ref(WEBSITE);

5、Other

  1. Because the multi-channel source code is in the variants directory, and src is the output directory of vite-plugin-variant, the files undder it will change at any time, so it is recommended to ignore src directory in the .gitignore file.
  2. vite-plugin-variant will automatically insert the necessary rules in the include option of tsconfig.json to avoid the code in the variants directory not being recognized by TypeScript and prompting an error.

License

MIT © GitLqr-2022