@db-ux/core-vite-plugin

中文文档
6.3.2发布于 2026/11/11Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 2821

Vite plugin for optimized DB UX Design System CSS imports

原始使用文档
文档目录18 节
  1. Installation
  2. Usage
  3. Basic Usage
  4. Advanced Usage
  5. Configuration
  6. include
  7. exclude
  8. optimize
  9. theme
  10. additionalLayers
  11. overrideLayers
  12. debug
  13. How it works
  14. Troubleshooting
  15. Plugin Order with Tailwind CSS
  16. CSS @property Warnings
  17. Styles Not Loading in Dev Mode with <link> Tags
  18. License

@db-ux/core-vite-plugin

Vite plugin for optimized DB UX Design System CSS imports. Automatically includes only the CSS you need based on components and classes used in your application.

Installation

npm install @db-ux/core-vite-plugin --save-dev

Usage

Basic Usage

Add the plugin to your vite.config.js or vite.config.ts:

import { defineConfig } from "vite";
import dbUxPlugin from "@db-ux/core-vite-plugin";

export default defineConfig({
    plugins: [dbUxPlugin()]
});

Then import the plugin in your CSS file:

/* styles.css or main.css */
@import "@db-ux/core-vite-plugin/index.css";

The plugin handles theme detection, component CSS, and foundation styles automatically.

Migration

If you're currently using the manual CSS layer imports, you can replace them with the plugin's single import:

/* Before */
@layer whitelabel-theme, db-ux;
@import "@db-ux/core-foundations/build/styles/theme/rollup.css"
    layer(whitelabel-theme);
@import "@db-ux/core-components/build/styles/bundle.css" layer(db-ux);
/* After */
@import "@db-ux/core-vite-plugin/index.css";

Advanced Usage

For more control, you can configure the plugin:

import { defineConfig } from "vite";
import dbUxPlugin from "@db-ux/core-vite-plugin";

export default defineConfig({
    plugins: [
        dbUxPlugin({
            include: {
                components: ["button", "input"], // Force include specific components
                foundations: ["helpers", "animations", "icons"], // Force include foundation features
                colors: ["neutral", "brand"], // Force include color schemes
                densities: ["regular", "functional"], // Force include densities
                fontSizes: ["body-md", "headline-lg"] // Force include font sizes
            },
            exclude: {
                components: ["tooltip"], // Exclude specific components
                foundations: ["elevation"], // Exclude foundation features
                colors: ["critical"], // Exclude color schemes
                densities: ["expressive"], // Exclude densities
                fontSizes: ["body-3xs"] // Exclude font sizes
            },
            optimize: true, // Remove unused CSS variable declarations to reduce bundle size (default: true).
            theme: "db-theme", // Specify preferred theme package name (e.g., "db-theme")
            additionalLayers: { after: ["ri-extension"] }, // Append custom layers to the auto-generated order
            debug: false // Generate detection report for debugging (default: false)
        })
    ]
});

Configuration

include

  • Type: { components?: Component[], foundations?: FoundationFeature[], colors?: ColorScheme[], densities?: Density[], fontSizes?: FontSize[] }
  • Force include specific components, foundation features, color schemes, densities, or font sizes
  • Foundation features: icons, helpers, elevation, animations, code

exclude

  • Type: { components?: Component[], foundations?: FoundationFeature[], colors?: ColorScheme[], densities?: Density[], fontSizes?: FontSize[] }
  • Exclude specific components, foundation features, color schemes, densities, or font sizes

optimize

  • Type: boolean
  • Default: true
  • Remove unused CSS variable declarations to reduce bundle size

theme

  • Type: string
  • Default: undefined
  • Specify a preferred theme package name (e.g., "db-theme"). The plugin automatically detects installed theme packages from @db-ux/*-theme or @db-ux-inner-source/*-theme. Use this option to select a specific theme when multiple are available.

additionalLayers

  • Type: { before?: string[], after?: string[] }
  • Default: undefined
  • Append custom CSS cascade layers before or after the auto-generated layer order. Useful when your project defines its own layers on top of DB UX.
// Adds layers around the auto-generated ones
dbUxPlugin({
    additionalLayers: {
        before: ["reset"],
        after: ["ri-extension"]
    }
});
// → @layer reset, db-theme, db-ux, ri-extension;

overrideLayers

  • Type: string[]
  • Default: undefined
  • Fully replace the auto-generated @layer statement with a custom layer order. When set, additionalLayers is ignored.
dbUxPlugin({
    overrideLayers: ["db-theme", "db-ux", "ri-extension"]
});
// → @layer db-theme, db-ux, ri-extension;

debug

  • Type: boolean
  • Default: false
  • Generate a db-ux-detection-report.json file in the project root directory for debugging purposes. This report contains all detected components, colors, densities, and font sizes. Useful for troubleshooting optimization issues.

How it works

The plugin analyzes your source files to detect:

  • DB UX component usage (e.g., class="db-button")
  • Custom classes using design tokens
  • Explicitly configured includes/excludes

It then generates an optimized CSS bundle containing only:

  • Required foundation styles (theme, fonts, icons)
  • Component styles for detected components
  • Optional features based on configuration

Troubleshooting

Plugin Order with Tailwind CSS

If you're using Tailwind CSS alongside this plugin, the order matters. The @db-ux/core-vite-plugin must be placed before the Tailwind plugin in your Vite configuration:

import { defineConfig } from "vite";
import dbUxPlugin from "@db-ux/core-vite-plugin";
import tailwindcss from "@tailwindcss/vite";

export default defineConfig({
    plugins: [
        dbUxPlugin(), // Must come before tailwindcss()
        tailwindcss()
    ]
});

And in your CSS file:

@import "tailwindcss";
@import "@db-ux/core-vite-plugin/index.css";

Why? The DB UX plugin needs to process and replace the @import "@db-ux/core-vite-plugin/index.css" statement with actual CSS before Tailwind processes the file. Tailwind will strip out unrecognized imports, so the DB UX plugin must run first to transform the import into valid CSS that Tailwind can then process.

CSS @property Warnings

You may see warnings about "Unknown at rule: @property" in your build output or IDE. These are informational warnings from CSS parsers that don't yet fully support the CSS Houdini @property at-rule. These warnings don't affect functionality - the @property rule is valid CSS and works correctly in modern browsers. You can safely ignore these warnings or configure your CSS linter to suppress them.

If you load your CSS via a <link> tag in index.html:

<!-- ❌ This won't work with the plugin in dev mode -->
<link rel="stylesheet" href="/src/styles.css" />

The plugin's transform hook only runs for CSS that is part of Vite's module graph. Static <link> tags are served as-is by Vite's dev server, so the @import "@db-ux/core-vite-plugin/index.css" inside the CSS file is never processed.

Solution: Import the CSS from your JavaScript/TypeScript entry file instead:

// main.ts or main.tsx
import "./styles.css";

This pulls the CSS into Vite's module graph where the plugin can transform it. The production build is not affected by this issue.

License

This project is licensed under Apache-2.0.

版本与发布记录

@db-ux/core-vite-plugin 共发布 79 个版本,首次发布于 2026/02/19;过去 12 个月发布了 79 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
6.3.2latest2026/11/11今天
6.3.12026/11/101 天前
6.3.02026/11/056 天前
6.2.12026/11/047 天前
6.2.1-optimized-icon-fonts-amount2-b78987enext2026/11/047 天前
6.2.02026/10/2913 天前

关于 @db-ux/core-vite-plugin 的常见问题

@db-ux/core-vite-plugin 是什么?

Vite plugin for optimized DB UX Design System CSS imports

如何安装 @db-ux/core-vite-plugin?

在项目目录运行 npm install @db-ux/core-vite-plugin,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vite(>=4.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@db-ux/core-vite-plugin 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@db-ux/core-vite-plugin 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@db-ux/core-vite-plugin 可以商用吗?

@db-ux/core-vite-plugin 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@db-ux/core-vite-plugin 的下载量有多少?

根据 npm 官方下载统计,@db-ux/core-vite-plugin 在 2026/10/12 – 2026/11/10 这 30 天内被下载 2,821 次,日均约 94 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@db-ux/core-vite-plugin 还在维护吗?

最新版本 6.3.2 发布于 2026/11/11(今天);至今共发布 79 个版本,其中过去 12 个月发布了 79 个;首次发布于 2026/02/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。