bem-refactor

将 Vue 组件重构为使用 BEM(Block-Element-Modifier)命名规范。 使用场景: - 用户说"用 useBEM 改造这个组件" - 用户说"给这个组件加上 BEM 类名" - 用户要求重构组件以符合项目 BEM 规范 - 需要将 Tailwind 工具类与 BEM 语义类名结合使用 触发关键词:useBEM、BEM、重构组件、BEM 改造、bem-refactor

Best use case

bem-refactor is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

将 Vue 组件重构为使用 BEM(Block-Element-Modifier)命名规范。 使用场景: - 用户说"用 useBEM 改造这个组件" - 用户说"给这个组件加上 BEM 类名" - 用户要求重构组件以符合项目 BEM 规范 - 需要将 Tailwind 工具类与 BEM 语义类名结合使用 触发关键词:useBEM、BEM、重构组件、BEM 改造、bem-refactor

Teams using bem-refactor should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/bem-refactor/SKILL.md --create-dirs "https://raw.githubusercontent.com/Lionad-Morotar/local-tools/main/local-link/skills/bem-refactor/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/bem-refactor/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How bem-refactor Compares

Feature / Agentbem-refactorStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

将 Vue 组件重构为使用 BEM(Block-Element-Modifier)命名规范。 使用场景: - 用户说"用 useBEM 改造这个组件" - 用户说"给这个组件加上 BEM 类名" - 用户要求重构组件以符合项目 BEM 规范 - 需要将 Tailwind 工具类与 BEM 语义类名结合使用 触发关键词:useBEM、BEM、重构组件、BEM 改造、bem-refactor

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# BEM 组件重构指南

## 工作流程

### 1. 分析现有代码

读取目标文件,了解:
- 组件结构和层级关系
- 现有的 class 命名方式
- 是否需要保留 Tailwind 工具类

### 2. 查找项目 BEM 规范

搜索项目中的 useBEM 使用方式:
- 查找 `useBEM` 的实现位置(通常在 `app/composables/bem/`)
- 查看 CONVENTIONS.md 中的 BEM 命名规范
- 了解项目约定的 block 前缀(如 `page-*`, `cmpt-*`, `layout-*`)

### 3. 确定 Block 名称

根据组件类型和位置,选择合适的 block 名:

| 组件类型 | Block 前缀示例 |
|---------|--------------|
| 页面级组件 | `page-xxx` |
| 可复用 UI 组件 | `cmpt-xxx` |
| 布局组件 | `layout-xxx` |

### 4. 重构模板

引入 useBEM:

```ts
const { b, e, is } = useBEM('block-name')
```

类名绑定规则:
- **静态 Tailwind 类名** → 使用 `class`
- **动态 BEM 类名** → 使用 `:class`

示例:

```vue
<!-- Before -->
<div class="px-6 py-4 bg-white rounded-sm">
  <h2 class="text-lg font-semibold text-gray-900">标题</h2>
</div>

<!-- After -->
<div class="px-6 py-4 bg-white rounded-sm" :class="e('header')">
  <h2 class="text-lg font-semibold text-gray-900" :class="e('title')">标题</h2>
</div>
```

### 5. 添加 Style Block

在组件末尾添加嵌套 BEM 结构的 style 占位:

```vue
<style scoped lang="css">
.p-block-name {
  /* container */

  &__header {
    /* header wrapper */

    &-inner {
      /* header inner */
    }
  }

  &__title {
    /* title element */
  }

  &__main {
    /* main content */

    &.is-empty {
      /* modifier state */
    }
  }
}
</style>
```

## 完整示例

**重构前:**

```vue
<template>
  <div class="w-full">
    <div class="px-6 py-4 bg-white rounded-sm">
      <h2 class="text-lg font-semibold">{{ title }}</h2>
    </div>
    <div class="main bg-white rounded-sm">
      <slot />
    </div>
  </div>
</template>
```

**重构后:**

```vue
<script setup lang="ts">
const { b, e, is } = useBEM('page-saas')

const props = defineProps<{
  title?: string
}>()
</script>

<template>
  <div class="w-full" :class="b()">
    <div class="px-6 py-4 bg-white rounded-sm" :class="e('header')">
      <h2 class="text-lg font-semibold" :class="e('title')">{{ title }}</h2>
    </div>
    <div class="bg-white rounded-sm" :class="e('main')">
      <slot />
    </div>
  </div>
</template>

<style scoped lang="css">
.p-page-saas {
  /* container */

  &__header {
    /* header wrapper */
  }

  &__title {
    /* page title */
  }

  &__main {
    /* main content */
  }
}
</style>
```

## 注意事项

1. **保留 Tailwind 类名**:如果项目使用 Tailwind,保留工具类用于实际样式,BEM 类名用于语义标记
2. **v-tw-merge 指令**:在根元素上使用 `v-tw-merge` 指令确保 class 合并正确
3. **状态修饰符**:使用 `is('state')` 生成状态类名(如 `is-empty`)
4. **空规则占位**:在 style block 中使用注释占位,避免 lint 警告

Related Skills

css-refactor

7
from Lionad-Morotar/local-tools

Upgrade legacy CSS to modern standards. Scans stylesheets for outdated patterns (floats, clearfix, vendor prefixes, old flexbox syntax, px media queries, @import, !important abuse) and replaces them with modern equivalents. Introduces cascade layers, extracts design tokens, and consolidates redundancy. Use when refactoring CSS, modernizing stylesheets, upgrading legacy code, removing vendor prefixes, or replacing floats with grid/flexbox.

open-u-dashboard

7
from Lionad-Morotar/local-tools

open understand dashboard for user

sync-template-skill

7
from Lionad-Morotar/local-tools

这是一个技能文件的模板,展示了技能的基本结构和内容组织方式。

talk-humanize

7
from Lionad-Morotar/local-tools

Be direct and informative. No filler, no fluff, but give enough to be useful.

search-web

7
from Lionad-Morotar/local-tools

使用 Evaluator-optimizer 模式进行系统性多轮网络搜索,采用结构化 Ask 流程在搜索前澄清研究目标。基于 YC Office Hours 的提问方法论,确保搜索方向清晰、结果可验证。当用户需要深入调查复杂主题、验证假设或全面收集信息时使用。

save-to-eagle

7
from Lionad-Morotar/local-tools

归档网络内容到 Eagle 素材库。支持:(1) Behance/Pixiv 图片归档,(2) 网页视频录制(页面动画、滚动录制)。使用方式:'归档 [URL]' 归档图片;'录制网页视频 [URL]' 录制页面动画;'滚动录制 [URL]' 自动滚动截图。支持评分如 '归档 [URL], 3/5'。

save-ob-chaos

7
from Lionad-Morotar/local-tools

将对话内容快速存档到 Obsidian Chaos 文件夹。触发词:"存档到 Obsidian"、"保存到 Chaos"、"ob 存档"、"记下这个"、"保存这段内容"、"存到 chaos"。

save-ob-chaos-mermaid

7
from Lionad-Morotar/local-tools

将 Mermaid 图表保存到 Obsidian Chaos 文件夹。触发词:"保存 mermaid 到 chaos"、"mermaid 存档"。

save-ob-chaos-excalidraw

7
from Lionad-Morotar/local-tools

绘制 Excalidraw 图表并存档到 Obsidian Chaos 文件夹。触发词:"画个图存到 Obsidian"、"excalidraw 存档"、"画个流程图保存"、"画图存到 chaos"、"创建图表并存档"、"画架构图到 ob"。

release-project

7
from Lionad-Morotar/local-tools

项目版本发布流程指导,帮助用户完成版本规划、Changelog 管理、版本号升级、Git 标签创建和 npm 首次发布准备。Use when: (1) 用户需要发布新版本 (2) 需要创建版本发布流程 (3) 需要管理版本号和 Changelog (4) 需要自动化版本发布 (5) 需要检查 release 分支同步 (6) 首次 npm 发布准备

recognize-codebase-branch-flow

7
from Lionad-Morotar/local-tools

识别并记忆项目 git 分支模型

rebase-commits

7
from Lionad-Morotar/local-tools

将零散的 commits 整合为清晰的逻辑提交,使 Git 历史更易读。 Use when: (1) 用户说 "rebase commits"、"整理提交历史"、"让历史更干净" (2) 用户想将多个相关 commits 合并为逻辑单元 (3) 完成一个功能后需要清理 commit 历史 (4) 提交历史混乱,需要重新组织