@brandocms/vite-plugin-europacss

中文文档
0.1.0-beta.0发布于 2026/10/16MITTypeScriptES Module近 30 天下载 2390

Vite adapter for the standalone EuropaCSS compiler

原始使用文档

EuropaCSS native compiler adapter for Vite

Native beta package. Supports Vite 6.4.3 and 8.3.0+ on Node 22.12+ and Node 24+. The compiler remains a standalone Rust executable; this optional JavaScript adapter only connects it to Vite. There are no N-API bindings or JavaScript config evaluation.

Install the matching adapter and CLI beta in your application:

pnpm add -D --save-exact @brandocms/[email protected] @brandocms/[email protected]

The adapter has an exact dependency on the CLI package. It resolves the native executable from that dependency without searching PATH. Installing the CLI directly also exposes pnpm exec europa for migration and other commands. Platform binaries come from npm optional dependencies, with no install scripts, Rust toolchain or separate binary downloads. Keep optional dependencies enabled.

The HTML docs source has the complete application workflow.

import { defineConfig } from 'vite';
import europa from '@brandocms/vite-plugin-europacss';

export default defineConfig({
  plugins: [europa({
    config: './europa.json5',
    targets: ['defaults'], // One CSS policy for Europa and Vite.
    // Optional: only compile your own stylesheet entry points.
    include: (filename) => filename.replaceAll('\\', '/').endsWith('/css/app.css'),
  })],
  css: {
    devSourcemap: true,
    // Suppresses discovery of an old postcss.config.cjs.
    postcss: { plugins: [] },
  },
  build: { sourcemap: true, cssMinify: 'lightningcss' },
});

Keep your normal import '../css/app.css'. Remove the old Europa PostCSS plugin and any custom Europa config reload plugin. Convert static configuration first:

europa migrate-config europa.config.cjs -o europa.json5

If other PostCSS plugins are still needed, retain those in your PostCSS config and omit the empty inline css.postcss setting. The adapter does not modify Vite's PostCSS settings. Vite itself may still use PostCSS internally.

Options are documented in index.d.ts. The default executable is the packaged compiler; the default config is europa.json5 relative to Vite's root. Use config: false for Europa defaults. Browser target queries go in targets.

The native executable resolves that CSS policy once at Vite startup. The adapter shares the resulting engine floors with Europa, build.cssTarget and css.lightningcss.targets, replacing separate CSS targets and legacy-plugin CSS defaults. JavaScript targets and legacy bundles are unchanged. Both CSS passes remain enabled. Vite 6 requires installing lightningcss in the application for the final minifier shown above; Vite 8 includes it as a regular dependency. The adapter preserves your minifier choice.

Modern Android and Samsung Internet targets map to Chromium; patch floors round down to major/minor in both passes. Unsupported stock Android and unknown Samsung releases fail explicitly. See the target policy details. For compiler development, binary: '/absolute/path/to/europacss/target/release/europa' overrides the packaged compiler. The executable must support europa bridge targets.

CSS is compiled before Vite's CSS pipeline. Vite still handles CSS modules, asset URLs, extraction, minification and style injection. Ordinary CSS imports are bundled by Rust. For imports that are not exact local files, the adapter asks Vite to resolve package exports and aliases, then passes absolute paths to Rust. Layer/supports/media qualifiers, source maps, and per-file asset rebasing are retained. Globs and virtual/SFC imports are unsupported. ?raw and ?url requests are deliberately left to Vite.

Local imports and JSON5 configuration, including the complete extends chain, are watched. Normal edits update affected CSS modules through HMR; file creation/deletion uses a full reload to recover missing inputs. Vite ignores node_modules, so the adapter polls only the used dependency files there and reloads when they change. Removed dependencies stop triggering updates, and server.watch: null disables this polling. See config inheritance for sharing a preset with local overrides. Compiler errors retain their original filename/line/column. Source maps locate individual declarations and Europa directives when their origin is unambiguous. A shorthand combined from several authored declarations keeps the containing rule's location. Rules that Lightning CSS does not map, such as keyframe steps, remain unmapped. Unreliable backend columns after non-ASCII text on the same generated line are also left unmapped rather than pointing at an unrelated rule.

For font token labels in Chrome's Styles pane, enable europa({ debugTokens: true }). The development CSS includes comments such as:

font-size: 20px; /* --ec-font-token: "typography.sizes.body"; */

Chrome recognizes the declaration inside this comment as a disabled property, so the token label appears alongside the size without changing computed styles. Labels identify sizes generated by @fontsize and the size argument of @font, including responsive variants. Literal sizes and ambiguous merged origins have no label. Labels are always omitted from Vite production builds, including builds with cssMinify: false.

Use Vite's default CSS transformer with css.devSourcemap: true. A subsequent transformer such as css.transformer: 'lightningcss' can strip these comments and reduce source-map precision. The production setting build.cssMinify: 'lightningcss' is fine.

The adapter launches one target-resolution process at startup and one process per CSS compilation (30-second timeout), with no generated CSS files. The europa bridge protocol accepts one JSON request on stdin and emits one versioned JSON response on stdout. Failed responses include attempted import paths, so a newly created missing dependency can recover a build.

For local tests, run cargo build -p europacss, then npm ci and npm test in the parent packages/ workspace using Node 22 or 24. EUROPA_BINARY can select another compiled executable. Release tarballs are built with python3 scripts/package-npm.py --shared from the repository root.

版本与发布记录

@brandocms/vite-plugin-europacss 共发布 2 个版本,首次发布于 2026/10/16;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.1.0-beta.0latest2026/10/1624 天前
0.0.0-stage2026/10/1624 天前

关于 @brandocms/vite-plugin-europacss 的常见问题

@brandocms/vite-plugin-europacss 是什么?

Vite adapter for the standalone EuropaCSS compiler

如何安装 @brandocms/vite-plugin-europacss?

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

@brandocms/vite-plugin-europacss 支持 TypeScript 吗?

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

@brandocms/vite-plugin-europacss 支持 ESM 还是 CommonJS?

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

@brandocms/vite-plugin-europacss 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.12.0 || >=24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@brandocms/vite-plugin-europacss 可以商用吗?

@brandocms/vite-plugin-europacss 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@brandocms/vite-plugin-europacss 的下载量有多少?

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

@brandocms/vite-plugin-europacss 还在维护吗?

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