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-auto-login

v4.2.0

Published

Vite plugin for automatic login during development

Downloads

144

Readme

vite-plugin-auto-login

一个 Vite 插件,用于在开发服务器启动时自动执行登录流程,获取访问令牌并更新到环境变量文件。

安装

npm install vite-plugin-auto-login --save-dev

快速开始

  1. 克隆仓库并构建插件:
git clone <repository-url>
cd vite-plugin-auto-login
npm run setup
  1. 运行示例:
# 基础示例
npm run examples:basic

# 高级示例
npm run examples:advanced

使用

vite.config.ts 文件中配置插件:

import { defineConfig } from 'vite';
import autoLogin from 'vite-plugin-auto-login';

export default defineConfig({
  plugins: [
    autoLogin({
      // 认证凭据
      username: 'your-username',
      password: 'your-password',
      
      // 可选:自定义 API 端点
      // baseUrl: 'https://your-api.com',
      // loginPath: '/login',
      // tokenPath: '/token',
      // authPath: '/user/info',
      
      // 可选:环境变量配置
      // envFile: '.env.development.local', // 默认根据 NODE_ENV 自动确定
      // tokenKey: 'VITE_ACCESS_TOKEN', // 存储令牌的环境变量键名
      
      // 可选:行为配置
      // enabled: true, // 是否启用插件
      // silent: false, // 是否静默模式(不输出日志)
      // timeout: 10000, // 请求超时时间(毫秒)
    })
  ]
});

环境变量

你也可以通过环境变量来配置插件:

# .env 文件
VITE_AUTO_LOGIN_USERNAME=your-username
VITE_AUTO_LOGIN_PASSWORD=your-password
VITE_AUTO_LOGIN_REQUEST_SECRET=your-request-secret
VITE_AUTO_LOGIN_BASE_URL=https://your-api.com
VITE_AUTO_LOGIN_LOGIN_PATH=/login
VITE_AUTO_LOGIN_TOKEN_PATH=/token
VITE_AUTO_LOGIN_AUTH_PATH=/user/info
VITE_AUTO_LOGIN_ENABLED=true
VITE_AUTO_LOGIN_TOKEN_KEY=VITE_ACCESS_TOKEN

工作原理

  1. 插件在 Vite 开发服务器启动时自动执行
  2. 调用登录 API 获取 requestSecret 和 secretSign
  3. 使用 requestSecret 和 secretSign 调用获取令牌 API
  4. 将获取的 access_token 写入到 .env.[environment].local 文件中
  5. 应用可以通过环境变量使用这个令牌

配置选项

| 选项 | 类型 | 默认值 | 说明 | |------|------|--------|------| | username | string | - | 登录用户名 | | password | string | - | 登录密码 | | loginType | 'PASSWORD' \| 'MOBILE' | 'PASSWORD' | 登录类型 | | requestSecret | string | '' | 请求密钥 | | createCompany | 0 \| 1 | 0 | 是否创建公司 | | baseUrl | string | 'https://cs-utwin.bwton-console.cn' | API 基础地址 | | loginPath | string | '/oauth2/website/userLogin' | 登录 API 路径 | | tokenPath | string | '/oauth2/website/getAccessToken' | 获取令牌 API 路径 | | authPath | string | '/api/enterpriseadmin/v1/user/info' | 用户信息验证 API 路径 | | envFile | string | .env.[mode].local | 环境变量文件路径 | | tokenKey | string | 'VITE_ACCESS_TOKEN' | 存储令牌的环境变量键名 | | enabled | boolean | true | 是否启用插件 | | silent | boolean | false | 是否静默模式(不输出日志) | | timeout | number | 10000 | 请求超时时间(毫秒) |

许可证

MIT