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

@vte-js/vite-plugin

v1.0.1

Published

Vite plugin for Vue Token Engine - compile <style token> to CSS Variables

Readme

@vte-js/vite-plugin

Vue Token Engine 的 Vite 插件,支持在 Vue SFC 中使用 <style token> 语法。

安装

npm install @vte-js/vite-plugin
# 或
pnpm add @vte-js/vite-plugin

快速开始

// vite.config.ts
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vte from "@vte-js/vite-plugin";

export default defineConfig({
  plugins: [
    vue(),
    vte(),
  ],
});

SFC 语法

<style token>

在 Vue SFC 中使用 <style token> 块编写 token-based 样式:

<template>
  <button class="btn">Click me</button>
</template>

<style token>
.btn {
  background: $semantic.color.primary;
  padding: $semantic.spacing.medium;
}
</style>

编译后输出:

.btn {
  background: var(--vte-semantic-color-primary);
  padding: var(--vte-semantic-spacing-medium);
}

:root {
  --vte-semantic-color-primary: #3b82f6;
  --vte-semantic-spacing-medium: 0.5rem;
}

<style token scoped>

支持 Vue scoped styles:

<style token scoped>
.btn {
  background: $semantic.color.primary;
}
</style>

编译后输出:

.btn[data-v-xxx] {
  background: var(--vte-semantic-color-primary);
}

带引号的 Token 路径

支持包含连字符的 token 路径:

<style token>
.btn:hover {
  background: $semantic.color."primary-hover";
}
</style>

编译后输出:

.btn:hover {
  background: var(--vte-semantic-color-primary-hover);
}

配置选项

vte({
  // token 文件路径(相对于项目根目录)
  tokenFile: "design-tokens.ts",

  // 目标平台: "web" | "mp" | "rn"
  platform: "web",

  // Sourcemap 配置
  sourcemap: true, // true | "inline" | "hidden" | false

  // 构建时输出配置
  output: {
    types: true,      // 生成 tokens.d.ts(TypeScript 类型声明)
    css: true,        // 生成 tokens.css(CSS 变量定义)
    agentJson: true,  // 生成 tokens.agent.json(AI 可读格式)
    prefix: "tokens", // 输出文件名前缀(默认 "tokens")
  },
})

配置选项详情

| 选项 | 类型 | 默认值 | 说明 | |------|------|--------|------| | tokenFile | string | "design-tokens.ts" | Token 文件路径 | | platform | string | "web" | 目标平台:"web" | "mp" | "rn" | | sourcemap | boolean \| string | true | Sourcemap 配置 | | output.types | boolean | true | 生成 tokens.d.ts | | output.css | boolean | true | 生成 tokens.css | | output.agentJson | boolean | true | 生成 tokens.agent.json | | output.prefix | string | "tokens" | 输出文件名前缀 |

自定义前缀示例

vte({
  output: {
    prefix: "design-tokens",
  },
})
// 生成: design-tokens.css, design-tokens.d.ts, design-tokens.agent.json

禁用特定输出

vte({
  output: {
    types: false,    // 不生成 .d.ts
    css: false,      // 不生成 .css
    agentJson: true, // 只生成 .agent.json
  },
})

Sourcemap 配置

vte({
  sourcemap: true,   // 生成 .map 文件(默认)
  sourcemap: "inline", // 内联 sourcemap
  sourcemap: "hidden", // 生成 .map 文件但不引用
  sourcemap: false,  // 禁用 sourcemap
})

注意:需要在 Vite 配置中也启用 sourcemap:

export default defineConfig({
  build: {
    sourcemap: true,
  },
})

构建产物

构建后会在 dist 目录生成以下文件:

dist/
├── index.html          # HTML 入口
├── assets/
│   ├── index-*.css     # 编译后的 CSS(token 已替换)
│   └── index-*.js      # 编译后的 JS
├── tokens.css          # CSS 变量定义文件
├── tokens.d.ts         # TypeScript 类型声明
└── tokens.agent.json   # AI 可读的 token 信息

平台支持

Web(默认)

输出 CSS Variables,通过 :root 注入:

:root {
  --vte-semantic-color-primary: #3b82f6;
}
.btn {
  background: var(--vte-semantic-color-primary);
}

小程序 (mp)

直接内联值,不使用 CSS Variables:

.btn {
  background: #3b82f6;
}

React Native

输出 StyleSheet 格式:

export const tokens = {
  semantic: {
    color: { primary: "#3b82f6" },
  },
};

错误提示

当使用不存在的 token 时,插件会输出警告并提供修复建议:

⚠ [VTE] Unknown token: "$semantic.colr.primary"
   Did you mean:
     - $semantic.color.primary
     - $semantic.color.text

热重载

修改 design-tokens.ts 文件后,插件会自动触发 full-reload。

验证 CSS 语法

由于 VTE 使用自定义的 $token 语法,VS Code 的 CSS 语言服务器会报告语法错误。建议在项目中添加 .vscode/settings.json

{
  "css.validate": false,
  "scss.validate": false,
  "less.validate": false
}

License

ISC