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

@web-baseline/nuxt-css-layer

v1.0.0

Published

Use css cascade layers in Nuxt

Readme

Nuxt CSS layer (@web-baseline/nuxt-css-layer)

npm version npm downloads Codecov License Nuxt

✨ 在 Nuxt 中使用 CSS 级联层 ✨

兼容 Nuxt 4。

English | 简体中文

特性

  • 通过 ?layer= 查询参数为导入的 CSS 指定层名
    • 在 Vue 单文件组件中,<style layer="..."> 会被转换为对应的 ?layer= 请求参数后处理
  • 通过规则匹配(rules)批量为 CSS 文件分配层名
  • 通过服务端注入的 @layer 声明统一层级顺序

快速开始

使用一个命令将模块安装到 Nuxt 应用程序中:

npx nuxi module add @web-baseline/nuxt-css-layer

就是这样!现在,您可以在 Nuxt 应用程序中使用 CSS 级联层 ✨

使用方式

1)配置模块

// nuxt.config.ts
export default defineNuxtConfig({
	modules: ['@web-baseline/nuxt-css-layer'],
	cssLayer: {
		rules: [
			{
				includes: /^node_modules\/element-plus/,
				layerName: 'element-plus',
			},
		],
		cssLayerOrder: ['base', 'element-plus', 'app'],
	},
})

2)通过导入查询参数声明层

// app.vue / 任意入口文件
import './theme.css?layer=base'

3)在 Vue SFC 的 style 块声明层

<style scoped layer="app">
.app-root {
	color: red;
}
</style>

importQuery 默认开启时,会识别 SFC style 请求中的 layer 查询参数,因此可直接在 <style> 块上使用 layer 属性。

已知问题(SFC layer 空属性)

当在 SFC 中使用 <style layer>(未显式指定层名)时,受 Vite 生成 style 请求 id 的方式影响,会被转换为 layer=true

由于查询参数中无法区分字符串与布尔值,该场景下最终会生成名为 true 的级联层。

如果你期望生成匿名层,请将层名设置为单个空格:

<style layer=" ">
/* anonymous layer */
</style>

4)可选:统一全局层顺序

当配置了 cssLayerOrder 后,模块会在 SSR 的 <head> 中注入:

@layer base, element-plus, app;

这样可以确保应用样式与三方库样式的层叠顺序稳定可控。

配置

| 配置项 | 描述 | 类型 | 默认值 | | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ----------- | | importQuery | 是否启用对 ?layer= 的解析(同时控制普通 CSS 导入与 SFC <style layer="..."> 的层处理) | boolean | true | | rules | 基于规则将 CSS 文件映射到层名(继承 @web-baseline/postcss-wrap-up-layerrules) | PostcssWrapUpLayerOptions['rules'] | [] | | ignoreOnlyComments | 是否忽略仅包含注释的文件(透传给 postcss-wrap-up-layer) | boolean \| undefined | undefined | | cssLayerOrder | 级联层排序 | string \| string[] \| undefined | undefined |

工作原理

  • importQuery:注册 PostCSS 插件,从导入查询参数读取 layer(例如 a.css?layer=base)。
  • SFC 的 <style layer="..."> 也会落到同一条 ?layer= 查询参数解析链路,因此同样受 importQuery 开关控制。
  • rules:额外注册一组基于文件路径匹配的 PostCSS 规则。
  • cssLayerOrder:生成 Nitro 服务端插件,在 SSR HTML 头部注入 @layer 声明。

本地开发

pnpm dev          # 运行 playground
pnpm lint         # ESLint 校验
pnpm test         # 单元 + e2e 测试
pnpm build        # 完整构建流程